diff --git a/contracts/mutants/BSCPool/1/BLR/BSCPool.sol b/contracts/mutants/BSCPool/1/BLR/BSCPool.sol new file mode 100644 index 00000000000..0a5823224e2 --- /dev/null +++ b/contracts/mutants/BSCPool/1/BLR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = true; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/BOR/BSCPool.sol b/contracts/mutants/BSCPool/1/BOR/BSCPool.sol new file mode 100644 index 00000000000..1417b9f0cc0 --- /dev/null +++ b/contracts/mutants/BSCPool/1/BOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/CCD/BSCPool.sol b/contracts/mutants/BSCPool/1/CCD/BSCPool.sol new file mode 100644 index 00000000000..7cdada78d20 --- /dev/null +++ b/contracts/mutants/BSCPool/1/CCD/BSCPool.sol @@ -0,0 +1,507 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/CSC/BSCPool.sol b/contracts/mutants/BSCPool/1/CSC/BSCPool.sol new file mode 100644 index 00000000000..9cfed5d9cab --- /dev/null +++ b/contracts/mutants/BSCPool/1/CSC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (true) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/DLR/BSCPool.sol b/contracts/mutants/BSCPool/1/DLR/BSCPool.sol new file mode 100644 index 00000000000..9a1d0835070 --- /dev/null +++ b/contracts/mutants/BSCPool/1/DLR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo memory pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/ECS/BSCPool.sol b/contracts/mutants/BSCPool/1/ECS/BSCPool.sol new file mode 100644 index 00000000000..2febd215d8b --- /dev/null +++ b/contracts/mutants/BSCPool/1/ECS/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint8(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/EED/BSCPool.sol b/contracts/mutants/BSCPool/1/EED/BSCPool.sol new file mode 100644 index 00000000000..a4798cd6531 --- /dev/null +++ b/contracts/mutants/BSCPool/1/EED/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + /* emit Deposit(_user, _pid, _amount); */ + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/EHC/BSCPool.sol b/contracts/mutants/BSCPool/1/EHC/BSCPool.sol new file mode 100644 index 00000000000..4db19fd940e --- /dev/null +++ b/contracts/mutants/BSCPool/1/EHC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/ETR/BSCPool.sol b/contracts/mutants/BSCPool/1/ETR/BSCPool.sol new file mode 100644 index 00000000000..185a3a64a21 --- /dev/null +++ b/contracts/mutants/BSCPool/1/ETR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.send(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/FVR/BSCPool.sol b/contracts/mutants/BSCPool/1/FVR/BSCPool.sol new file mode 100644 index 00000000000..abfb89c9b26 --- /dev/null +++ b/contracts/mutants/BSCPool/1/FVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) internal { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/GVR/BSCPool.sol b/contracts/mutants/BSCPool/1/GVR/BSCPool.sol new file mode 100644 index 00000000000..070b76c8aa2 --- /dev/null +++ b/contracts/mutants/BSCPool/1/GVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.difficulty > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/ILR/BSCPool.sol b/contracts/mutants/BSCPool/1/ILR/BSCPool.sol new file mode 100644 index 00000000000..64388ccb80a --- /dev/null +++ b/contracts/mutants/BSCPool/1/ILR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 1; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/MOI/BSCPool.sol b/contracts/mutants/BSCPool/1/MOI/BSCPool.sol new file mode 100644 index 00000000000..eec55563f5b --- /dev/null +++ b/contracts/mutants/BSCPool/1/MOI/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public onlyOwner { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/MOR/BSCPool.sol b/contracts/mutants/BSCPool/1/MOR/BSCPool.sol new file mode 100644 index 00000000000..ebf1061b225 --- /dev/null +++ b/contracts/mutants/BSCPool/1/MOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public notPause { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/RSD/BSCPool.sol b/contracts/mutants/BSCPool/1/RSD/BSCPool.sol new file mode 100644 index 00000000000..e6f54f71079 --- /dev/null +++ b/contracts/mutants/BSCPool/1/RSD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + /* return poolInfo.length; */ + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/SFR/BSCPool.sol b/contracts/mutants/BSCPool/1/SFR/BSCPool.sol new file mode 100644 index 00000000000..e3ae402c687 --- /dev/null +++ b/contracts/mutants/BSCPool/1/SFR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.sub(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/TOR/BSCPool.sol b/contracts/mutants/BSCPool/1/TOR/BSCPool.sol new file mode 100644 index 00000000000..64fc74dfc16 --- /dev/null +++ b/contracts/mutants/BSCPool/1/TOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(tx.origin), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/UORD/BSCPool.sol b/contracts/mutants/BSCPool/1/UORD/BSCPool.sol new file mode 100644 index 00000000000..a7ee3b0bec7 --- /dev/null +++ b/contracts/mutants/BSCPool/1/UORD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256( 1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/1/VVR/BSCPool.sol b/contracts/mutants/BSCPool/1/VVR/BSCPool.sol new file mode 100644 index 00000000000..094a2c2c06a --- /dev/null +++ b/contracts/mutants/BSCPool/1/VVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet public _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/10/BOR/BSCPool.sol b/contracts/mutants/BSCPool/10/BOR/BSCPool.sol new file mode 100644 index 00000000000..e42e540ceba --- /dev/null +++ b/contracts/mutants/BSCPool/10/BOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index < getBlackListLength() + 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP > address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid < getMultLPLength() + 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken > address(0) || _multLpChef > address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/10/CSC/BSCPool.sol b/contracts/mutants/BSCPool/10/CSC/BSCPool.sol new file mode 100644 index 00000000000..c915dcc2573 --- /dev/null +++ b/contracts/mutants/BSCPool/10/CSC/BSCPool.sol @@ -0,0 +1,509 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (true) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (true) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (true) { + return 0; + } + if (true) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (true) { + return; + } + uint256 lpSupply; + if (true) { + if (true) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (true) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (true) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/10/DLR/BSCPool.sol b/contracts/mutants/BSCPool/10/DLR/BSCPool.sol new file mode 100644 index 00000000000..cfceb1436ae --- /dev/null +++ b/contracts/mutants/BSCPool/10/DLR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo memory pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo memory user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo memory user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo memory pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo memory user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/10/EHC/BSCPool.sol b/contracts/mutants/BSCPool/10/EHC/BSCPool.sol new file mode 100644 index 00000000000..273082f3ed6 --- /dev/null +++ b/contracts/mutants/BSCPool/10/EHC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + /* require(_index <= getBlackListLength() - 1, "index out of bounds"); */ + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + /* require(_addLP != address(0), "LP is the zero address"); */ + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + /* require(_pid <= getMultLPLength() - 1, "not find this multLP"); */ + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + /* require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); */ + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + /* require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); */ + /* require(paused == true, "No mining suspension"); */ + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + /* require(address(_lpToken) != address(0), "_lpToken is the zero address"); */ + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + /* require(_pid <= poolLength() - 1, "not find this pool"); */ + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/10/FVR/BSCPool.sol b/contracts/mutants/BSCPool/10/FVR/BSCPool.sol new file mode 100644 index 00000000000..7fa65dbadf4 --- /dev/null +++ b/contracts/mutants/BSCPool/10/FVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) internal { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) external onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) external onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() external view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) external onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) external onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() external view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) external view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) external view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) external onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/10/GVR/BSCPool.sol b/contracts/mutants/BSCPool/10/GVR/BSCPool.sol new file mode 100644 index 00000000000..c62ecd97dd0 --- /dev/null +++ b/contracts/mutants/BSCPool/10/GVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.difficulty > startBlock ? block.difficulty : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.difficulty); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.difficulty.sub(_lastRewardBlock)).mul(reward(block.difficulty))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.difficulty <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.difficulty; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.difficulty; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.difficulty; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.difficulty > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/10/ILR/BSCPool.sol b/contracts/mutants/BSCPool/10/ILR/BSCPool.sol new file mode 100644 index 00000000000..09d2a883d1e --- /dev/null +++ b/contracts/mutants/BSCPool/10/ILR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 1; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670399; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 0, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(1), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(0)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 0, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(1) && _multLpChef != address(1), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/10/MOR/BSCPool.sol b/contracts/mutants/BSCPool/10/MOR/BSCPool.sol new file mode 100644 index 00000000000..4dcbf4d1522 --- /dev/null +++ b/contracts/mutants/BSCPool/10/MOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public notPause { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public notPause { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view notPause returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public notPause returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public notPause { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public notPause { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public notPause { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public notPause { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/10/RSD/BSCPool.sol b/contracts/mutants/BSCPool/10/RSD/BSCPool.sol new file mode 100644 index 00000000000..2ceea674b6c --- /dev/null +++ b/contracts/mutants/BSCPool/10/RSD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + /* return poolInfo.length; */ + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.add(_blackList, _bad); */ + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.remove(_blackList, _bad); */ + } + + function getBlackListLength() public view returns (uint256) { + /* return EnumerableSet.length(_blackList); */ + } + + function isBadAddress(address account) public view returns (bool) { + /* return EnumerableSet.contains(_blackList, account); */ + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + /* return EnumerableSet.at(_blackList, _index); */ + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + /* return EnumerableSet.add(_multLP, _addLP); */ + } + + function isMultLP(address _LP) public view returns (bool) { + /* return EnumerableSet.contains(_multLP, _LP); */ + } + + function getMultLPLength() public view returns (uint256) { + /* return EnumerableSet.length(_multLP); */ + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + /* return EnumerableSet.at(_multLP, _pid); */ + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/10/SFR/BSCPool.sol b/contracts/mutants/BSCPool/10/SFR/BSCPool.sol new file mode 100644 index 00000000000..293b1a4ded6 --- /dev/null +++ b/contracts/mutants/BSCPool/10/SFR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.sub(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.sub(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.sub(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).sub(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).mul(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.mul(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).sub(startBlock); + blockReward = blockReward.sub((r.sub(_lastRewardBlock)).add(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.sub((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/10/VVR/BSCPool.sol b/contracts/mutants/BSCPool/10/VVR/BSCPool.sol new file mode 100644 index 00000000000..0437eaaadf0 --- /dev/null +++ b/contracts/mutants/BSCPool/10/VVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet public _multLP; + EnumerableSet.AddressSet public _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx internal mdx; + // MDX tokens created per block. + uint256 internal mdxPerBlock; + // Info of each pool. + PoolInfo[] internal poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool internal paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 internal totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 internal startBlock; + // multLP MasterChef + address internal multLpChef; + // multLP Token + address internal multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/BLR/BSCPool.sol b/contracts/mutants/BSCPool/2/BLR/BSCPool.sol new file mode 100644 index 00000000000..e4d00cd79ab --- /dev/null +++ b/contracts/mutants/BSCPool/2/BLR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = true; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == false, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/BOR/BSCPool.sol b/contracts/mutants/BSCPool/2/BOR/BSCPool.sol new file mode 100644 index 00000000000..23b6fc8aeb4 --- /dev/null +++ b/contracts/mutants/BSCPool/2/BOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/CSC/BSCPool.sol b/contracts/mutants/BSCPool/2/CSC/BSCPool.sol new file mode 100644 index 00000000000..d9f81267e1d --- /dev/null +++ b/contracts/mutants/BSCPool/2/CSC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (true) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (true) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/DLR/BSCPool.sol b/contracts/mutants/BSCPool/2/DLR/BSCPool.sol new file mode 100644 index 00000000000..e11d9c96557 --- /dev/null +++ b/contracts/mutants/BSCPool/2/DLR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo memory pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/EED/BSCPool.sol b/contracts/mutants/BSCPool/2/EED/BSCPool.sol new file mode 100644 index 00000000000..c3f5308d9d3 --- /dev/null +++ b/contracts/mutants/BSCPool/2/EED/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + /* emit Deposit(_user, _pid, _amount); */ + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + /* emit Deposit(_user, _pid, _amount); */ + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/EHC/BSCPool.sol b/contracts/mutants/BSCPool/2/EHC/BSCPool.sol new file mode 100644 index 00000000000..58a55c4d2c5 --- /dev/null +++ b/contracts/mutants/BSCPool/2/EHC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/ETR/BSCPool.sol b/contracts/mutants/BSCPool/2/ETR/BSCPool.sol new file mode 100644 index 00000000000..67b59935d2b --- /dev/null +++ b/contracts/mutants/BSCPool/2/ETR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.send(_to, mdxBal); + } else { + mdx.send(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/FVR/BSCPool.sol b/contracts/mutants/BSCPool/2/FVR/BSCPool.sol new file mode 100644 index 00000000000..785f03520e4 --- /dev/null +++ b/contracts/mutants/BSCPool/2/FVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) internal { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) external onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/GVR/BSCPool.sol b/contracts/mutants/BSCPool/2/GVR/BSCPool.sol new file mode 100644 index 00000000000..3c143bb4229 --- /dev/null +++ b/contracts/mutants/BSCPool/2/GVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.difficulty > startBlock ? block.difficulty : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/ILR/BSCPool.sol b/contracts/mutants/BSCPool/2/ILR/BSCPool.sol new file mode 100644 index 00000000000..fd9ccb84c6a --- /dev/null +++ b/contracts/mutants/BSCPool/2/ILR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 1; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670399; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/MOI/BSCPool.sol b/contracts/mutants/BSCPool/2/MOI/BSCPool.sol new file mode 100644 index 00000000000..08b56bfc956 --- /dev/null +++ b/contracts/mutants/BSCPool/2/MOI/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public onlyOwner { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/MOR/BSCPool.sol b/contracts/mutants/BSCPool/2/MOR/BSCPool.sol new file mode 100644 index 00000000000..d0ce58e3abf --- /dev/null +++ b/contracts/mutants/BSCPool/2/MOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public notPause { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public notPause { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/RSD/BSCPool.sol b/contracts/mutants/BSCPool/2/RSD/BSCPool.sol new file mode 100644 index 00000000000..d41b668d707 --- /dev/null +++ b/contracts/mutants/BSCPool/2/RSD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + /* return poolInfo.length; */ + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.add(_blackList, _bad); */ + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/SFR/BSCPool.sol b/contracts/mutants/BSCPool/2/SFR/BSCPool.sol new file mode 100644 index 00000000000..547cb326de6 --- /dev/null +++ b/contracts/mutants/BSCPool/2/SFR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.sub(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.sub(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/TOR/BSCPool.sol b/contracts/mutants/BSCPool/2/TOR/BSCPool.sol new file mode 100644 index 00000000000..8a5f84b858f --- /dev/null +++ b/contracts/mutants/BSCPool/2/TOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(tx.origin), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, tx.origin); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/UORD/BSCPool.sol b/contracts/mutants/BSCPool/2/UORD/BSCPool.sol new file mode 100644 index 00000000000..cf92279a7e4 --- /dev/null +++ b/contracts/mutants/BSCPool/2/UORD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256( 1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/2/VVR/BSCPool.sol b/contracts/mutants/BSCPool/2/VVR/BSCPool.sol new file mode 100644 index 00000000000..440ebddbc97 --- /dev/null +++ b/contracts/mutants/BSCPool/2/VVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet public _multLP; + EnumerableSet.AddressSet public _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/BLR/BSCPool.sol b/contracts/mutants/BSCPool/3/BLR/BSCPool.sol new file mode 100644 index 00000000000..ee986aabac6 --- /dev/null +++ b/contracts/mutants/BSCPool/3/BLR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = true; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == false, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == true, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/BOR/BSCPool.sol b/contracts/mutants/BSCPool/3/BOR/BSCPool.sol new file mode 100644 index 00000000000..831596b1041 --- /dev/null +++ b/contracts/mutants/BSCPool/3/BOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index < getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/CSC/BSCPool.sol b/contracts/mutants/BSCPool/3/CSC/BSCPool.sol new file mode 100644 index 00000000000..0cdc1425bee --- /dev/null +++ b/contracts/mutants/BSCPool/3/CSC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (true) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (true) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (true) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/DLR/BSCPool.sol b/contracts/mutants/BSCPool/3/DLR/BSCPool.sol new file mode 100644 index 00000000000..73b18ac5235 --- /dev/null +++ b/contracts/mutants/BSCPool/3/DLR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo memory pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/EED/BSCPool.sol b/contracts/mutants/BSCPool/3/EED/BSCPool.sol new file mode 100644 index 00000000000..e6b125b50cd --- /dev/null +++ b/contracts/mutants/BSCPool/3/EED/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + /* emit Deposit(_user, _pid, _amount); */ + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + /* emit Deposit(_user, _pid, _amount); */ + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + /* emit Withdraw(_user, _pid, _amount); */ + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/EHC/BSCPool.sol b/contracts/mutants/BSCPool/3/EHC/BSCPool.sol new file mode 100644 index 00000000000..007e630b61f --- /dev/null +++ b/contracts/mutants/BSCPool/3/EHC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + /* require(_index <= getBlackListLength() - 1, "index out of bounds"); */ + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/FVR/BSCPool.sol b/contracts/mutants/BSCPool/3/FVR/BSCPool.sol new file mode 100644 index 00000000000..808ce521031 --- /dev/null +++ b/contracts/mutants/BSCPool/3/FVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) internal { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) external onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) external onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/GVR/BSCPool.sol b/contracts/mutants/BSCPool/3/GVR/BSCPool.sol new file mode 100644 index 00000000000..926544dc144 --- /dev/null +++ b/contracts/mutants/BSCPool/3/GVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.difficulty > startBlock ? block.difficulty : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.difficulty); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/ILR/BSCPool.sol b/contracts/mutants/BSCPool/3/ILR/BSCPool.sol new file mode 100644 index 00000000000..e224dd4dde8 --- /dev/null +++ b/contracts/mutants/BSCPool/3/ILR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 1; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670399; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/MOI/BSCPool.sol b/contracts/mutants/BSCPool/3/MOI/BSCPool.sol new file mode 100644 index 00000000000..df414638523 --- /dev/null +++ b/contracts/mutants/BSCPool/3/MOI/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public onlyOwner { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/MOR/BSCPool.sol b/contracts/mutants/BSCPool/3/MOR/BSCPool.sol new file mode 100644 index 00000000000..ceeee0a9650 --- /dev/null +++ b/contracts/mutants/BSCPool/3/MOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public notPause { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public notPause { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/RSD/BSCPool.sol b/contracts/mutants/BSCPool/3/RSD/BSCPool.sol new file mode 100644 index 00000000000..d104b78015b --- /dev/null +++ b/contracts/mutants/BSCPool/3/RSD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + /* return poolInfo.length; */ + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.add(_blackList, _bad); */ + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.remove(_blackList, _bad); */ + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/SFR/BSCPool.sol b/contracts/mutants/BSCPool/3/SFR/BSCPool.sol new file mode 100644 index 00000000000..0771addb307 --- /dev/null +++ b/contracts/mutants/BSCPool/3/SFR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.sub(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.sub(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.sub(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/TOR/BSCPool.sol b/contracts/mutants/BSCPool/3/TOR/BSCPool.sol new file mode 100644 index 00000000000..931e814ad5e --- /dev/null +++ b/contracts/mutants/BSCPool/3/TOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(tx.origin), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, tx.origin); + } else { + depositMdx(_pid, _amount, tx.origin); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/UORD/BSCPool.sol b/contracts/mutants/BSCPool/3/UORD/BSCPool.sol new file mode 100644 index 00000000000..2515f26828d --- /dev/null +++ b/contracts/mutants/BSCPool/3/UORD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256( 1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length++; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/3/VVR/BSCPool.sol b/contracts/mutants/BSCPool/3/VVR/BSCPool.sol new file mode 100644 index 00000000000..ab4a509a6ee --- /dev/null +++ b/contracts/mutants/BSCPool/3/VVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet public _multLP; + EnumerableSet.AddressSet public _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx internal mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/BOR/BSCPool.sol b/contracts/mutants/BSCPool/4/BOR/BSCPool.sol new file mode 100644 index 00000000000..b8bebf2ce50 --- /dev/null +++ b/contracts/mutants/BSCPool/4/BOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index < getBlackListLength() + 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/CSC/BSCPool.sol b/contracts/mutants/BSCPool/4/CSC/BSCPool.sol new file mode 100644 index 00000000000..c44187a75db --- /dev/null +++ b/contracts/mutants/BSCPool/4/CSC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (true) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (true) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (true) { + return 0; + } + if (true) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/DLR/BSCPool.sol b/contracts/mutants/BSCPool/4/DLR/BSCPool.sol new file mode 100644 index 00000000000..dcead66b932 --- /dev/null +++ b/contracts/mutants/BSCPool/4/DLR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo memory pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo memory user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/EED/BSCPool.sol b/contracts/mutants/BSCPool/4/EED/BSCPool.sol new file mode 100644 index 00000000000..51faeb63462 --- /dev/null +++ b/contracts/mutants/BSCPool/4/EED/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + /* emit Deposit(_user, _pid, _amount); */ + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + /* emit Deposit(_user, _pid, _amount); */ + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + /* emit Withdraw(_user, _pid, _amount); */ + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + /* emit Withdraw(_user, _pid, _amount); */ + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/EHC/BSCPool.sol b/contracts/mutants/BSCPool/4/EHC/BSCPool.sol new file mode 100644 index 00000000000..0caadd36b6a --- /dev/null +++ b/contracts/mutants/BSCPool/4/EHC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + /* require(_index <= getBlackListLength() - 1, "index out of bounds"); */ + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + /* require(_addLP != address(0), "LP is the zero address"); */ + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/FVR/BSCPool.sol b/contracts/mutants/BSCPool/4/FVR/BSCPool.sol new file mode 100644 index 00000000000..a582ac7bed9 --- /dev/null +++ b/contracts/mutants/BSCPool/4/FVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) internal { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) external onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) external onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() external view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/GVR/BSCPool.sol b/contracts/mutants/BSCPool/4/GVR/BSCPool.sol new file mode 100644 index 00000000000..fe67a093ae3 --- /dev/null +++ b/contracts/mutants/BSCPool/4/GVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.difficulty > startBlock ? block.difficulty : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.difficulty); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.difficulty.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/ILR/BSCPool.sol b/contracts/mutants/BSCPool/4/ILR/BSCPool.sol new file mode 100644 index 00000000000..c2bb3e0c43d --- /dev/null +++ b/contracts/mutants/BSCPool/4/ILR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 1; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670399; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/MOI/BSCPool.sol b/contracts/mutants/BSCPool/4/MOI/BSCPool.sol new file mode 100644 index 00000000000..8b623fe4a10 --- /dev/null +++ b/contracts/mutants/BSCPool/4/MOI/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public onlyOwner { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/MOR/BSCPool.sol b/contracts/mutants/BSCPool/4/MOR/BSCPool.sol new file mode 100644 index 00000000000..2fce829f5d1 --- /dev/null +++ b/contracts/mutants/BSCPool/4/MOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public notPause { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public notPause { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/RSD/BSCPool.sol b/contracts/mutants/BSCPool/4/RSD/BSCPool.sol new file mode 100644 index 00000000000..52486b792d6 --- /dev/null +++ b/contracts/mutants/BSCPool/4/RSD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + /* return poolInfo.length; */ + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.add(_blackList, _bad); */ + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.remove(_blackList, _bad); */ + } + + function getBlackListLength() public view returns (uint256) { + /* return EnumerableSet.length(_blackList); */ + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/SFR/BSCPool.sol b/contracts/mutants/BSCPool/4/SFR/BSCPool.sol new file mode 100644 index 00000000000..6bf493551b1 --- /dev/null +++ b/contracts/mutants/BSCPool/4/SFR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.sub(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.sub(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.sub(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).sub(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/TOR/BSCPool.sol b/contracts/mutants/BSCPool/4/TOR/BSCPool.sol new file mode 100644 index 00000000000..548f356a58f --- /dev/null +++ b/contracts/mutants/BSCPool/4/TOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(tx.origin), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, tx.origin); + } else { + depositMdx(_pid, _amount, tx.origin); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, tx.origin); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/UORD/BSCPool.sol b/contracts/mutants/BSCPool/4/UORD/BSCPool.sol new file mode 100644 index 00000000000..f0cd4b025fc --- /dev/null +++ b/contracts/mutants/BSCPool/4/UORD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256( 1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length++; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n--; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/4/VVR/BSCPool.sol b/contracts/mutants/BSCPool/4/VVR/BSCPool.sol new file mode 100644 index 00000000000..3fee489e8ea --- /dev/null +++ b/contracts/mutants/BSCPool/4/VVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet public _multLP; + EnumerableSet.AddressSet public _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx internal mdx; + // MDX tokens created per block. + uint256 internal mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/BOR/BSCPool.sol b/contracts/mutants/BSCPool/5/BOR/BSCPool.sol new file mode 100644 index 00000000000..19a0b9b4ab8 --- /dev/null +++ b/contracts/mutants/BSCPool/5/BOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index < getBlackListLength() + 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP > address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/CSC/BSCPool.sol b/contracts/mutants/BSCPool/5/CSC/BSCPool.sol new file mode 100644 index 00000000000..0e66fc775d7 --- /dev/null +++ b/contracts/mutants/BSCPool/5/CSC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (true) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (true) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (true) { + return 0; + } + if (true) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (true) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/DLR/BSCPool.sol b/contracts/mutants/BSCPool/5/DLR/BSCPool.sol new file mode 100644 index 00000000000..0c44f719b5e --- /dev/null +++ b/contracts/mutants/BSCPool/5/DLR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo memory pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo memory user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/EED/BSCPool.sol b/contracts/mutants/BSCPool/5/EED/BSCPool.sol new file mode 100644 index 00000000000..077776f95e3 --- /dev/null +++ b/contracts/mutants/BSCPool/5/EED/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + /* emit Deposit(_user, _pid, _amount); */ + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + /* emit Deposit(_user, _pid, _amount); */ + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + /* emit Withdraw(_user, _pid, _amount); */ + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + /* emit Withdraw(_user, _pid, _amount); */ + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + /* emit EmergencyWithdraw(_user, _pid, amount); */ + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/EHC/BSCPool.sol b/contracts/mutants/BSCPool/5/EHC/BSCPool.sol new file mode 100644 index 00000000000..92adf14e795 --- /dev/null +++ b/contracts/mutants/BSCPool/5/EHC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + /* require(_index <= getBlackListLength() - 1, "index out of bounds"); */ + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + /* require(_addLP != address(0), "LP is the zero address"); */ + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + /* require(_pid <= getMultLPLength() - 1, "not find this multLP"); */ + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/FVR/BSCPool.sol b/contracts/mutants/BSCPool/5/FVR/BSCPool.sol new file mode 100644 index 00000000000..6eb10de9d7e --- /dev/null +++ b/contracts/mutants/BSCPool/5/FVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) internal { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) external onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) external onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() external view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) external onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/GVR/BSCPool.sol b/contracts/mutants/BSCPool/5/GVR/BSCPool.sol new file mode 100644 index 00000000000..780de5ba703 --- /dev/null +++ b/contracts/mutants/BSCPool/5/GVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.difficulty > startBlock ? block.difficulty : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.difficulty); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.difficulty.sub(_lastRewardBlock)).mul(reward(block.difficulty))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/ILR/BSCPool.sol b/contracts/mutants/BSCPool/5/ILR/BSCPool.sol new file mode 100644 index 00000000000..38f73047306 --- /dev/null +++ b/contracts/mutants/BSCPool/5/ILR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 1; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670399; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 0, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/MOI/BSCPool.sol b/contracts/mutants/BSCPool/5/MOI/BSCPool.sol new file mode 100644 index 00000000000..3a408a2110e --- /dev/null +++ b/contracts/mutants/BSCPool/5/MOI/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public onlyOwner { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/MOR/BSCPool.sol b/contracts/mutants/BSCPool/5/MOR/BSCPool.sol new file mode 100644 index 00000000000..f3581bae094 --- /dev/null +++ b/contracts/mutants/BSCPool/5/MOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public notPause { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public notPause { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view notPause returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/RSD/BSCPool.sol b/contracts/mutants/BSCPool/5/RSD/BSCPool.sol new file mode 100644 index 00000000000..72c1a8fc021 --- /dev/null +++ b/contracts/mutants/BSCPool/5/RSD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + /* return poolInfo.length; */ + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.add(_blackList, _bad); */ + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.remove(_blackList, _bad); */ + } + + function getBlackListLength() public view returns (uint256) { + /* return EnumerableSet.length(_blackList); */ + } + + function isBadAddress(address account) public view returns (bool) { + /* return EnumerableSet.contains(_blackList, account); */ + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/SFR/BSCPool.sol b/contracts/mutants/BSCPool/5/SFR/BSCPool.sol new file mode 100644 index 00000000000..f8294bd7ee7 --- /dev/null +++ b/contracts/mutants/BSCPool/5/SFR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.sub(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.sub(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.sub(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).sub(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).mul(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/TOR/BSCPool.sol b/contracts/mutants/BSCPool/5/TOR/BSCPool.sol new file mode 100644 index 00000000000..ec60b682c6a --- /dev/null +++ b/contracts/mutants/BSCPool/5/TOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(tx.origin), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, tx.origin); + } else { + depositMdx(_pid, _amount, tx.origin); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, tx.origin); + } else { + withdrawMdx(_pid, _amount, tx.origin); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/UORD/BSCPool.sol b/contracts/mutants/BSCPool/5/UORD/BSCPool.sol new file mode 100644 index 00000000000..dd78b0a8131 --- /dev/null +++ b/contracts/mutants/BSCPool/5/UORD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256( 1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length++; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n--; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; --pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/5/VVR/BSCPool.sol b/contracts/mutants/BSCPool/5/VVR/BSCPool.sol new file mode 100644 index 00000000000..c78fd07a0d7 --- /dev/null +++ b/contracts/mutants/BSCPool/5/VVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet public _multLP; + EnumerableSet.AddressSet public _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx internal mdx; + // MDX tokens created per block. + uint256 internal mdxPerBlock; + // Info of each pool. + PoolInfo[] internal poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/BOR/BSCPool.sol b/contracts/mutants/BSCPool/6/BOR/BSCPool.sol new file mode 100644 index 00000000000..71a7d9ed04d --- /dev/null +++ b/contracts/mutants/BSCPool/6/BOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index < getBlackListLength() + 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP > address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid < getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/CSC/BSCPool.sol b/contracts/mutants/BSCPool/6/CSC/BSCPool.sol new file mode 100644 index 00000000000..8d253bc786a --- /dev/null +++ b/contracts/mutants/BSCPool/6/CSC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (true) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (true) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (true) { + return 0; + } + if (true) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (true) { + return; + } + uint256 lpSupply; + if (true) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/DLR/BSCPool.sol b/contracts/mutants/BSCPool/6/DLR/BSCPool.sol new file mode 100644 index 00000000000..54807f116da --- /dev/null +++ b/contracts/mutants/BSCPool/6/DLR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo memory pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo memory user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo memory user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/EED/BSCPool.sol b/contracts/mutants/BSCPool/6/EED/BSCPool.sol new file mode 100644 index 00000000000..30673ee3b11 --- /dev/null +++ b/contracts/mutants/BSCPool/6/EED/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + /* emit Deposit(_user, _pid, _amount); */ + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + /* emit Deposit(_user, _pid, _amount); */ + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + /* emit Withdraw(_user, _pid, _amount); */ + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + /* emit Withdraw(_user, _pid, _amount); */ + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + /* emit EmergencyWithdraw(_user, _pid, amount); */ + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + /* emit EmergencyWithdraw(_user, _pid, amount); */ + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/EHC/BSCPool.sol b/contracts/mutants/BSCPool/6/EHC/BSCPool.sol new file mode 100644 index 00000000000..c331fbfe440 --- /dev/null +++ b/contracts/mutants/BSCPool/6/EHC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + /* require(_index <= getBlackListLength() - 1, "index out of bounds"); */ + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + /* require(_addLP != address(0), "LP is the zero address"); */ + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + /* require(_pid <= getMultLPLength() - 1, "not find this multLP"); */ + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + /* require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); */ + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/FVR/BSCPool.sol b/contracts/mutants/BSCPool/6/FVR/BSCPool.sol new file mode 100644 index 00000000000..bfd1f207251 --- /dev/null +++ b/contracts/mutants/BSCPool/6/FVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) internal { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) external onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) external onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() external view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) external onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) external onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/GVR/BSCPool.sol b/contracts/mutants/BSCPool/6/GVR/BSCPool.sol new file mode 100644 index 00000000000..a92736e05b5 --- /dev/null +++ b/contracts/mutants/BSCPool/6/GVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.difficulty > startBlock ? block.difficulty : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.difficulty); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.difficulty.sub(_lastRewardBlock)).mul(reward(block.difficulty))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.difficulty <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/ILR/BSCPool.sol b/contracts/mutants/BSCPool/6/ILR/BSCPool.sol new file mode 100644 index 00000000000..449e2eb0790 --- /dev/null +++ b/contracts/mutants/BSCPool/6/ILR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 1; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670399; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 0, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(1), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/MOI/BSCPool.sol b/contracts/mutants/BSCPool/6/MOI/BSCPool.sol new file mode 100644 index 00000000000..7362a2afe13 --- /dev/null +++ b/contracts/mutants/BSCPool/6/MOI/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public onlyOwner { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/MOR/BSCPool.sol b/contracts/mutants/BSCPool/6/MOR/BSCPool.sol new file mode 100644 index 00000000000..6d700bc8a76 --- /dev/null +++ b/contracts/mutants/BSCPool/6/MOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public notPause { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public notPause { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view notPause returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public notPause returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/RSD/BSCPool.sol b/contracts/mutants/BSCPool/6/RSD/BSCPool.sol new file mode 100644 index 00000000000..bc000c45179 --- /dev/null +++ b/contracts/mutants/BSCPool/6/RSD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + /* return poolInfo.length; */ + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.add(_blackList, _bad); */ + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.remove(_blackList, _bad); */ + } + + function getBlackListLength() public view returns (uint256) { + /* return EnumerableSet.length(_blackList); */ + } + + function isBadAddress(address account) public view returns (bool) { + /* return EnumerableSet.contains(_blackList, account); */ + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + /* return EnumerableSet.at(_blackList, _index); */ + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/SFR/BSCPool.sol b/contracts/mutants/BSCPool/6/SFR/BSCPool.sol new file mode 100644 index 00000000000..1bbbdf47388 --- /dev/null +++ b/contracts/mutants/BSCPool/6/SFR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.sub(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.sub(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.sub(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).sub(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).mul(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.mul(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/TOR/BSCPool.sol b/contracts/mutants/BSCPool/6/TOR/BSCPool.sol new file mode 100644 index 00000000000..4070ea2af0d --- /dev/null +++ b/contracts/mutants/BSCPool/6/TOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(tx.origin), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, tx.origin); + } else { + depositMdx(_pid, _amount, tx.origin); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, tx.origin); + } else { + withdrawMdx(_pid, _amount, tx.origin); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, tx.origin); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/UORD/BSCPool.sol b/contracts/mutants/BSCPool/6/UORD/BSCPool.sol new file mode 100644 index 00000000000..5764eb88312 --- /dev/null +++ b/contracts/mutants/BSCPool/6/UORD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256( 1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length++; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n--; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; --pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require( isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/6/VVR/BSCPool.sol b/contracts/mutants/BSCPool/6/VVR/BSCPool.sol new file mode 100644 index 00000000000..83eee895971 --- /dev/null +++ b/contracts/mutants/BSCPool/6/VVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet public _multLP; + EnumerableSet.AddressSet public _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx internal mdx; + // MDX tokens created per block. + uint256 internal mdxPerBlock; + // Info of each pool. + PoolInfo[] internal poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool internal paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/7/BOR/BSCPool.sol b/contracts/mutants/BSCPool/7/BOR/BSCPool.sol new file mode 100644 index 00000000000..c4569dc2509 --- /dev/null +++ b/contracts/mutants/BSCPool/7/BOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index < getBlackListLength() + 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP > address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid < getMultLPLength() + 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/7/CSC/BSCPool.sol b/contracts/mutants/BSCPool/7/CSC/BSCPool.sol new file mode 100644 index 00000000000..bee61ffcfaf --- /dev/null +++ b/contracts/mutants/BSCPool/7/CSC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (true) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (true) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (true) { + return 0; + } + if (true) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (true) { + return; + } + uint256 lpSupply; + if (true) { + if (true) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/7/DLR/BSCPool.sol b/contracts/mutants/BSCPool/7/DLR/BSCPool.sol new file mode 100644 index 00000000000..2cae1435d2e --- /dev/null +++ b/contracts/mutants/BSCPool/7/DLR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo memory pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo memory user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo memory user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo memory pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/7/EHC/BSCPool.sol b/contracts/mutants/BSCPool/7/EHC/BSCPool.sol new file mode 100644 index 00000000000..a384e4181ec --- /dev/null +++ b/contracts/mutants/BSCPool/7/EHC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + /* require(_index <= getBlackListLength() - 1, "index out of bounds"); */ + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + /* require(_addLP != address(0), "LP is the zero address"); */ + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + /* require(_pid <= getMultLPLength() - 1, "not find this multLP"); */ + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + /* require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); */ + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + /* require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); */ + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/7/FVR/BSCPool.sol b/contracts/mutants/BSCPool/7/FVR/BSCPool.sol new file mode 100644 index 00000000000..f3ec51da977 --- /dev/null +++ b/contracts/mutants/BSCPool/7/FVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) internal { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) external onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) external onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() external view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) external onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) external onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() external view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/7/GVR/BSCPool.sol b/contracts/mutants/BSCPool/7/GVR/BSCPool.sol new file mode 100644 index 00000000000..56de3efe864 --- /dev/null +++ b/contracts/mutants/BSCPool/7/GVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.difficulty > startBlock ? block.difficulty : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.difficulty); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.difficulty.sub(_lastRewardBlock)).mul(reward(block.difficulty))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.difficulty <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.difficulty; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/7/ILR/BSCPool.sol b/contracts/mutants/BSCPool/7/ILR/BSCPool.sol new file mode 100644 index 00000000000..5c99569e864 --- /dev/null +++ b/contracts/mutants/BSCPool/7/ILR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 1; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670399; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 0, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(1), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(0)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/7/MOI/BSCPool.sol b/contracts/mutants/BSCPool/7/MOI/BSCPool.sol new file mode 100644 index 00000000000..d854f8285c6 --- /dev/null +++ b/contracts/mutants/BSCPool/7/MOI/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public onlyOwner { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/7/MOR/BSCPool.sol b/contracts/mutants/BSCPool/7/MOR/BSCPool.sol new file mode 100644 index 00000000000..3ff2732ef45 --- /dev/null +++ b/contracts/mutants/BSCPool/7/MOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public notPause { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public notPause { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view notPause returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public notPause returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public notPause { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/7/RSD/BSCPool.sol b/contracts/mutants/BSCPool/7/RSD/BSCPool.sol new file mode 100644 index 00000000000..2902db198c8 --- /dev/null +++ b/contracts/mutants/BSCPool/7/RSD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + /* return poolInfo.length; */ + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.add(_blackList, _bad); */ + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.remove(_blackList, _bad); */ + } + + function getBlackListLength() public view returns (uint256) { + /* return EnumerableSet.length(_blackList); */ + } + + function isBadAddress(address account) public view returns (bool) { + /* return EnumerableSet.contains(_blackList, account); */ + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + /* return EnumerableSet.at(_blackList, _index); */ + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + /* return EnumerableSet.add(_multLP, _addLP); */ + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/7/SFR/BSCPool.sol b/contracts/mutants/BSCPool/7/SFR/BSCPool.sol new file mode 100644 index 00000000000..b105977ba76 --- /dev/null +++ b/contracts/mutants/BSCPool/7/SFR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.sub(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.sub(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.sub(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).sub(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).mul(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.mul(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).sub(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/7/TOR/BSCPool.sol b/contracts/mutants/BSCPool/7/TOR/BSCPool.sol new file mode 100644 index 00000000000..c7459ea8a54 --- /dev/null +++ b/contracts/mutants/BSCPool/7/TOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(tx.origin), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, tx.origin); + } else { + depositMdx(_pid, _amount, tx.origin); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, tx.origin); + } else { + withdrawMdx(_pid, _amount, tx.origin); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, tx.origin); + } else { + emergencyWithdrawMdx(_pid, tx.origin); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/7/VVR/BSCPool.sol b/contracts/mutants/BSCPool/7/VVR/BSCPool.sol new file mode 100644 index 00000000000..469bf900060 --- /dev/null +++ b/contracts/mutants/BSCPool/7/VVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet public _multLP; + EnumerableSet.AddressSet public _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx internal mdx; + // MDX tokens created per block. + uint256 internal mdxPerBlock; + // Info of each pool. + PoolInfo[] internal poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool internal paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 internal totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/8/BOR/BSCPool.sol b/contracts/mutants/BSCPool/8/BOR/BSCPool.sol new file mode 100644 index 00000000000..ce682a1c68e --- /dev/null +++ b/contracts/mutants/BSCPool/8/BOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index < getBlackListLength() + 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP > address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid < getMultLPLength() + 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken > address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/8/CSC/BSCPool.sol b/contracts/mutants/BSCPool/8/CSC/BSCPool.sol new file mode 100644 index 00000000000..b13ca1a3ac8 --- /dev/null +++ b/contracts/mutants/BSCPool/8/CSC/BSCPool.sol @@ -0,0 +1,509 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (true) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (true) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (true) { + return 0; + } + if (true) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (true) { + return; + } + uint256 lpSupply; + if (true) { + if (true) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/8/DLR/BSCPool.sol b/contracts/mutants/BSCPool/8/DLR/BSCPool.sol new file mode 100644 index 00000000000..d9f505c97b4 --- /dev/null +++ b/contracts/mutants/BSCPool/8/DLR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo memory pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo memory user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo memory user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo memory pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/8/EHC/BSCPool.sol b/contracts/mutants/BSCPool/8/EHC/BSCPool.sol new file mode 100644 index 00000000000..e3882b6ff35 --- /dev/null +++ b/contracts/mutants/BSCPool/8/EHC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + /* require(_index <= getBlackListLength() - 1, "index out of bounds"); */ + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + /* require(_addLP != address(0), "LP is the zero address"); */ + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + /* require(_pid <= getMultLPLength() - 1, "not find this multLP"); */ + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + /* require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); */ + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + /* require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); */ + /* require(paused == true, "No mining suspension"); */ + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/8/FVR/BSCPool.sol b/contracts/mutants/BSCPool/8/FVR/BSCPool.sol new file mode 100644 index 00000000000..39d8501ca99 --- /dev/null +++ b/contracts/mutants/BSCPool/8/FVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) internal { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) external onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) external onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() external view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) external onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) external onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() external view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) external view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/8/GVR/BSCPool.sol b/contracts/mutants/BSCPool/8/GVR/BSCPool.sol new file mode 100644 index 00000000000..7bbd519da99 --- /dev/null +++ b/contracts/mutants/BSCPool/8/GVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.difficulty > startBlock ? block.difficulty : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.difficulty); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.difficulty.sub(_lastRewardBlock)).mul(reward(block.difficulty))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.difficulty <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.difficulty; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.difficulty; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/8/ILR/BSCPool.sol b/contracts/mutants/BSCPool/8/ILR/BSCPool.sol new file mode 100644 index 00000000000..6383fb040be --- /dev/null +++ b/contracts/mutants/BSCPool/8/ILR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 1; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670399; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 0, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(1), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(0)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 0, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/8/MOI/BSCPool.sol b/contracts/mutants/BSCPool/8/MOI/BSCPool.sol new file mode 100644 index 00000000000..951f89d4a29 --- /dev/null +++ b/contracts/mutants/BSCPool/8/MOI/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public onlyOwner { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/8/MOR/BSCPool.sol b/contracts/mutants/BSCPool/8/MOR/BSCPool.sol new file mode 100644 index 00000000000..515c2e3017d --- /dev/null +++ b/contracts/mutants/BSCPool/8/MOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public notPause { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public notPause { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view notPause returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public notPause returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public notPause { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public notPause { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/8/RSD/BSCPool.sol b/contracts/mutants/BSCPool/8/RSD/BSCPool.sol new file mode 100644 index 00000000000..bc46c14313d --- /dev/null +++ b/contracts/mutants/BSCPool/8/RSD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + /* return poolInfo.length; */ + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.add(_blackList, _bad); */ + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.remove(_blackList, _bad); */ + } + + function getBlackListLength() public view returns (uint256) { + /* return EnumerableSet.length(_blackList); */ + } + + function isBadAddress(address account) public view returns (bool) { + /* return EnumerableSet.contains(_blackList, account); */ + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + /* return EnumerableSet.at(_blackList, _index); */ + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + /* return EnumerableSet.add(_multLP, _addLP); */ + } + + function isMultLP(address _LP) public view returns (bool) { + /* return EnumerableSet.contains(_multLP, _LP); */ + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/8/SFR/BSCPool.sol b/contracts/mutants/BSCPool/8/SFR/BSCPool.sol new file mode 100644 index 00000000000..bd1b2564a0c --- /dev/null +++ b/contracts/mutants/BSCPool/8/SFR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.sub(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.sub(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.sub(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).sub(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).mul(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.mul(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).sub(startBlock); + blockReward = blockReward.sub((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/8/VVR/BSCPool.sol b/contracts/mutants/BSCPool/8/VVR/BSCPool.sol new file mode 100644 index 00000000000..6542fc4bb32 --- /dev/null +++ b/contracts/mutants/BSCPool/8/VVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet public _multLP; + EnumerableSet.AddressSet public _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx internal mdx; + // MDX tokens created per block. + uint256 internal mdxPerBlock; + // Info of each pool. + PoolInfo[] internal poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool internal paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 internal totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 internal startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/9/BOR/BSCPool.sol b/contracts/mutants/BSCPool/9/BOR/BSCPool.sol new file mode 100644 index 00000000000..15fc37061b5 --- /dev/null +++ b/contracts/mutants/BSCPool/9/BOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad > address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index < getBlackListLength() + 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP > address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid < getMultLPLength() + 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken > address(0) || _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/9/CSC/BSCPool.sol b/contracts/mutants/BSCPool/9/CSC/BSCPool.sol new file mode 100644 index 00000000000..ccd9a67f408 --- /dev/null +++ b/contracts/mutants/BSCPool/9/CSC/BSCPool.sol @@ -0,0 +1,509 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (true) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (true) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (true) { + return 0; + } + if (true) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (true) { + return; + } + uint256 lpSupply; + if (true) { + if (true) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (true) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/9/DLR/BSCPool.sol b/contracts/mutants/BSCPool/9/DLR/BSCPool.sol new file mode 100644 index 00000000000..0246e5ad0ac --- /dev/null +++ b/contracts/mutants/BSCPool/9/DLR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo memory pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo memory user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo memory user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo memory pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo memory pool = poolInfo[_pid]; + UserInfo memory user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/9/EHC/BSCPool.sol b/contracts/mutants/BSCPool/9/EHC/BSCPool.sol new file mode 100644 index 00000000000..521778f0d2b --- /dev/null +++ b/contracts/mutants/BSCPool/9/EHC/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + /* require(_bad != address(0), "_bad is the zero address"); */ + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + /* require(_index <= getBlackListLength() - 1, "index out of bounds"); */ + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + /* require(_addLP != address(0), "LP is the zero address"); */ + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + /* require(_pid <= getMultLPLength() - 1, "not find this multLP"); */ + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + /* require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); */ + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + /* require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); */ + /* require(paused == true, "No mining suspension"); */ + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + /* require(address(_lpToken) != address(0), "_lpToken is the zero address"); */ + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/9/FVR/BSCPool.sol b/contracts/mutants/BSCPool/9/FVR/BSCPool.sol new file mode 100644 index 00000000000..15ff8366d73 --- /dev/null +++ b/contracts/mutants/BSCPool/9/FVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) internal { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) external onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) external onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() external view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) external onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) external onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() external view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) external view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) external view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/9/GVR/BSCPool.sol b/contracts/mutants/BSCPool/9/GVR/BSCPool.sol new file mode 100644 index 00000000000..82e0bbd9b48 --- /dev/null +++ b/contracts/mutants/BSCPool/9/GVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.difficulty > startBlock ? block.difficulty : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.difficulty); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.difficulty.sub(_lastRewardBlock)).mul(reward(block.difficulty))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.difficulty <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.difficulty; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.difficulty; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.difficulty; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/9/ILR/BSCPool.sol b/contracts/mutants/BSCPool/9/ILR/BSCPool.sol new file mode 100644 index 00000000000..1ddd5402a79 --- /dev/null +++ b/contracts/mutants/BSCPool/9/ILR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 1; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670399; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(1), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 0, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(1), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(0)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 0, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(1) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/9/MOI/BSCPool.sol b/contracts/mutants/BSCPool/9/MOI/BSCPool.sol new file mode 100644 index 00000000000..fafd2a557e6 --- /dev/null +++ b/contracts/mutants/BSCPool/9/MOI/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public onlyOwner { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private onlyOwner { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal onlyOwner { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/9/MOR/BSCPool.sol b/contracts/mutants/BSCPool/9/MOR/BSCPool.sol new file mode 100644 index 00000000000..7471983a94b --- /dev/null +++ b/contracts/mutants/BSCPool/9/MOR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public notPause { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public notPause { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public notPause returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view notPause returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public notPause returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public notPause { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public notPause { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public notPause { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/9/RSD/BSCPool.sol b/contracts/mutants/BSCPool/9/RSD/BSCPool.sol new file mode 100644 index 00000000000..72dd2d1ac77 --- /dev/null +++ b/contracts/mutants/BSCPool/9/RSD/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + /* return poolInfo.length; */ + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.add(_blackList, _bad); */ + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + /* return EnumerableSet.remove(_blackList, _bad); */ + } + + function getBlackListLength() public view returns (uint256) { + /* return EnumerableSet.length(_blackList); */ + } + + function isBadAddress(address account) public view returns (bool) { + /* return EnumerableSet.contains(_blackList, account); */ + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + /* return EnumerableSet.at(_blackList, _index); */ + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + /* return EnumerableSet.add(_multLP, _addLP); */ + } + + function isMultLP(address _LP) public view returns (bool) { + /* return EnumerableSet.contains(_multLP, _LP); */ + } + + function getMultLPLength() public view returns (uint256) { + /* return EnumerableSet.length(_multLP); */ + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/9/SFR/BSCPool.sol b/contracts/mutants/BSCPool/9/SFR/BSCPool.sol new file mode 100644 index 00000000000..68f0c509f28 --- /dev/null +++ b/contracts/mutants/BSCPool/9/SFR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.sub(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.sub(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.sub(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).sub(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).mul(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.mul(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).sub(startBlock); + blockReward = blockReward.sub((r.sub(_lastRewardBlock)).add(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/9/VVR/BSCPool.sol b/contracts/mutants/BSCPool/9/VVR/BSCPool.sol new file mode 100644 index 00000000000..3900bef606e --- /dev/null +++ b/contracts/mutants/BSCPool/9/VVR/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet public _multLP; + EnumerableSet.AddressSet public _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx internal mdx; + // MDX tokens created per block. + uint256 internal mdxPerBlock; + // Info of each pool. + PoolInfo[] internal poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool internal paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 internal totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 internal startBlock; + // multLP MasterChef + address internal multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCPool/original/BSCPool.sol b/contracts/mutants/BSCPool/original/BSCPool.sol new file mode 100644 index 00000000000..9f791ed8b91 --- /dev/null +++ b/contracts/mutants/BSCPool/original/BSCPool.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.6.0; + +import "./EnumerableSet.sol"; +import "./IMdx.sol"; +import "./IMasterChefBSC.sol"; + +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/math/SafeMath.sol"; + +contract BSCPool is Ownable { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + using EnumerableSet for EnumerableSet.AddressSet; + EnumerableSet.AddressSet private _multLP; + EnumerableSet.AddressSet private _blackList; + + // Info of each user. + struct UserInfo { + uint256 amount; // How many LP tokens the user has provided. + uint256 rewardDebt; // Reward debt. + uint256 multLpRewardDebt; //multLp Reward debt. + } + + // Info of each pool. + struct PoolInfo { + IERC20 lpToken; // Address of LP token contract. + uint256 allocPoint; // How many allocation points assigned to this pool. MDXs to distribute per block. + uint256 lastRewardBlock; // Last block number that MDXs distribution occurs. + uint256 accMdxPerShare; // Accumulated MDXs per share, times 1e12. + uint256 accMultLpPerShare; //Accumulated multLp per share + uint256 totalAmount; // Total amount of current pool deposit. + } + + // The MDX Token! + IMdx public mdx; + // MDX tokens created per block. + uint256 public mdxPerBlock; + // Info of each pool. + PoolInfo[] public poolInfo; + // Info of each user that stakes LP tokens. + mapping(uint256 => mapping(address => UserInfo)) public userInfo; + // Corresponding to the pid of the multLP pool + mapping(uint256 => uint256) public poolCorrespond; + // pid corresponding address + mapping(address => uint256) public LpOfPid; + // Control mining + bool public paused = false; + // Total allocation points. Must be the sum of all allocation points in all pools. + uint256 public totalAllocPoint = 0; + // The block number when MDX mining starts. + uint256 public startBlock; + // multLP MasterChef + address public multLpChef; + // multLP Token + address public multLpToken; + // How many blocks are halved + uint256 public halvingPeriod = 1670400; + + event Deposit(address indexed user, uint256 indexed pid, uint256 amount); + event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); + event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); + + constructor( + IMdx _mdx, + uint256 _mdxPerBlock, + uint256 _startBlock + ) public { + mdx = _mdx; + mdxPerBlock = _mdxPerBlock; + startBlock = _startBlock; + } + + function setHalvingPeriod(uint256 _block) public onlyOwner { + halvingPeriod = _block; + } + + // Set the number of mdx produced by each block + function setMdxPerBlock(uint256 newPerBlock) public onlyOwner { + massUpdatePools(); + mdxPerBlock = newPerBlock; + } + + function poolLength() public view returns (uint256) { + return poolInfo.length; + } + + function addBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.add(_blackList, _bad); + } + + function delBadAddress(address _bad) public onlyOwner returns (bool) { + require(_bad != address(0), "_bad is the zero address"); + return EnumerableSet.remove(_blackList, _bad); + } + + function getBlackListLength() public view returns (uint256) { + return EnumerableSet.length(_blackList); + } + + function isBadAddress(address account) public view returns (bool) { + return EnumerableSet.contains(_blackList, account); + } + + function getBadAddress(uint256 _index) public view onlyOwner returns (address) { + require(_index <= getBlackListLength() - 1, "index out of bounds"); + return EnumerableSet.at(_blackList, _index); + } + + function addMultLP(address _addLP) public onlyOwner returns (bool) { + require(_addLP != address(0), "LP is the zero address"); + IERC20(_addLP).approve(multLpChef, uint256(-1)); + return EnumerableSet.add(_multLP, _addLP); + } + + function isMultLP(address _LP) public view returns (bool) { + return EnumerableSet.contains(_multLP, _LP); + } + + function getMultLPLength() public view returns (uint256) { + return EnumerableSet.length(_multLP); + } + + function getMultLPAddress(uint256 _pid) public view returns (address) { + require(_pid <= getMultLPLength() - 1, "not find this multLP"); + return EnumerableSet.at(_multLP, _pid); + } + + function setPause() public onlyOwner { + paused = !paused; + } + + function setMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + } + + function replaceMultLP(address _multLpToken, address _multLpChef) public onlyOwner { + require(_multLpToken != address(0) && _multLpChef != address(0), "is the zero address"); + require(paused == true, "No mining suspension"); + multLpToken = _multLpToken; + multLpChef = _multLpChef; + uint256 length = getMultLPLength(); + while (length > 0) { + address dAddress = EnumerableSet.at(_multLP, 0); + uint256 pid = LpOfPid[dAddress]; + IMasterChefBSC(multLpChef).emergencyWithdraw(poolCorrespond[pid]); + EnumerableSet.remove(_multLP, dAddress); + length--; + } + } + + // Add a new lp to the pool. Can only be called by the owner. + // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do. + function add( + uint256 _allocPoint, + IERC20 _lpToken, + bool _withUpdate + ) public onlyOwner { + require(address(_lpToken) != address(0), "_lpToken is the zero address"); + if (_withUpdate) { + massUpdatePools(); + } + uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; + totalAllocPoint = totalAllocPoint.add(_allocPoint); + poolInfo.push( + PoolInfo({ + lpToken: _lpToken, + allocPoint: _allocPoint, + lastRewardBlock: lastRewardBlock, + accMdxPerShare: 0, + accMultLpPerShare: 0, + totalAmount: 0 + }) + ); + LpOfPid[address(_lpToken)] = poolLength() - 1; + } + + // Update the given pool's MDX allocation point. Can only be called by the owner. + function set( + uint256 _pid, + uint256 _allocPoint, + bool _withUpdate + ) public onlyOwner { + if (_withUpdate) { + massUpdatePools(); + } + totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); + poolInfo[_pid].allocPoint = _allocPoint; + } + + // The current pool corresponds to the pid of the multLP pool + function setPoolCorr(uint256 _pid, uint256 _sid) public onlyOwner { + require(_pid <= poolLength() - 1, "not find this pool"); + poolCorrespond[_pid] = _sid; + } + + function phase(uint256 blockNumber) public view returns (uint256) { + if (halvingPeriod == 0) { + return 0; + } + if (blockNumber > startBlock) { + return (blockNumber.sub(startBlock).sub(1)).div(halvingPeriod); + } + return 0; + } + + function reward(uint256 blockNumber) public view returns (uint256) { + uint256 _phase = phase(blockNumber); + return mdxPerBlock.div(2**_phase); + } + + function getMdxBlockReward(uint256 _lastRewardBlock) public view returns (uint256) { + uint256 blockReward = 0; + uint256 n = phase(_lastRewardBlock); + uint256 m = phase(block.number); + while (n < m) { + n++; + uint256 r = n.mul(halvingPeriod).add(startBlock); + blockReward = blockReward.add((r.sub(_lastRewardBlock)).mul(reward(r))); + _lastRewardBlock = r; + } + blockReward = blockReward.add((block.number.sub(_lastRewardBlock)).mul(reward(block.number))); + return blockReward; + } + + // Update reward variables for all pools. Be careful of gas spending! + function massUpdatePools() public { + uint256 length = poolInfo.length; + for (uint256 pid = 0; pid < length; ++pid) { + updatePool(pid); + } + } + + // Update reward variables of the given pool to be up-to-date. + function updatePool(uint256 _pid) public { + PoolInfo storage pool = poolInfo[_pid]; + if (block.number <= pool.lastRewardBlock) { + return; + } + uint256 lpSupply; + if (isMultLP(address(pool.lpToken))) { + if (pool.totalAmount == 0) { + pool.lastRewardBlock = block.number; + return; + } + lpSupply = pool.totalAmount; + } else { + lpSupply = pool.lpToken.balanceOf(address(this)); + if (lpSupply == 0) { + pool.lastRewardBlock = block.number; + return; + } + } + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + if (blockReward <= 0) { + return; + } + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + bool minRet = mdx.mint(address(this), mdxReward); + if (minRet) { + pool.accMdxPerShare = pool.accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + } + pool.lastRewardBlock = block.number; + } + + // View function to see pending MDXs on frontend. + function pending(uint256 _pid, address _user) external view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + (uint256 mdxAmount, uint256 tokenAmount) = pendingMdxAndToken(_pid, _user); + return (mdxAmount, tokenAmount); + } else { + uint256 mdxAmount = pendingMdx(_pid, _user); + return (mdxAmount, 0); + } + } + + function pendingMdxAndToken(uint256 _pid, address _user) private view returns (uint256, uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 accMultLpPerShare = pool.accMultLpPerShare; + if (user.amount > 0) { + uint256 TokenPending = IMasterChefBSC(multLpChef).pendingCake(poolCorrespond[_pid], address(this)); + accMultLpPerShare = accMultLpPerShare.add(TokenPending.mul(1e12).div(pool.totalAmount)); + uint256 userPending = user.amount.mul(accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(pool.totalAmount)); + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + if (block.number == pool.lastRewardBlock) { + return (user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt), userPending); + } + } + return (0, 0); + } + + function pendingMdx(uint256 _pid, address _user) private view returns (uint256) { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 accMdxPerShare = pool.accMdxPerShare; + uint256 lpSupply = pool.lpToken.balanceOf(address(this)); + if (user.amount > 0) { + if (block.number > pool.lastRewardBlock) { + uint256 blockReward = getMdxBlockReward(pool.lastRewardBlock); + uint256 mdxReward = blockReward.mul(pool.allocPoint).div(totalAllocPoint); + accMdxPerShare = accMdxPerShare.add(mdxReward.mul(1e12).div(lpSupply)); + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + if (block.number == pool.lastRewardBlock) { + return user.amount.mul(accMdxPerShare).div(1e12).sub(user.rewardDebt); + } + } + return 0; + } + + // Deposit LP tokens to BSCPool for MDX allocation. + function deposit(uint256 _pid, uint256 _amount) public notPause { + require(!isBadAddress(msg.sender), "Illegal, rejected "); + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + depositMdxAndToken(_pid, _amount, msg.sender); + } else { + depositMdx(_pid, _amount, msg.sender); + } + } + + function depositMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], 0); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + if (pool.totalAmount == 0) { + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } else { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).deposit(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add( + afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount) + ); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + function depositMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + updatePool(_pid); + if (user.amount > 0) { + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + } + if (_amount > 0) { + pool.lpToken.safeTransferFrom(_user, address(this), _amount); + user.amount = user.amount.add(_amount); + pool.totalAmount = pool.totalAmount.add(_amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Deposit(_user, _pid, _amount); + } + + // Withdraw LP tokens from BSCPool. + function withdraw(uint256 _pid, uint256 _amount) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + withdrawMdxAndToken(_pid, _amount, msg.sender); + } else { + withdrawMdx(_pid, _amount, msg.sender); + } + } + + function withdrawMdxAndToken( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdxAndToken: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], _amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + uint256 tokenPending = user.amount.mul(pool.accMultLpPerShare).div(1e12).sub(user.multLpRewardDebt); + if (tokenPending > 0) { + IERC20(multLpToken).safeTransfer(_user, tokenPending); + } + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + user.multLpRewardDebt = user.amount.mul(pool.accMultLpPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + function withdrawMdx( + uint256 _pid, + uint256 _amount, + address _user + ) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + require(user.amount >= _amount, "withdrawMdx: not good"); + updatePool(_pid); + uint256 pendingAmount = user.amount.mul(pool.accMdxPerShare).div(1e12).sub(user.rewardDebt); + if (pendingAmount > 0) { + safeMdxTransfer(_user, pendingAmount); + } + if (_amount > 0) { + user.amount = user.amount.sub(_amount); + pool.totalAmount = pool.totalAmount.sub(_amount); + pool.lpToken.safeTransfer(_user, _amount); + } + user.rewardDebt = user.amount.mul(pool.accMdxPerShare).div(1e12); + emit Withdraw(_user, _pid, _amount); + } + + // Withdraw without caring about rewards. EMERGENCY ONLY. + function emergencyWithdraw(uint256 _pid) public notPause { + PoolInfo storage pool = poolInfo[_pid]; + if (isMultLP(address(pool.lpToken))) { + emergencyWithdrawMdxAndToken(_pid, msg.sender); + } else { + emergencyWithdrawMdx(_pid, msg.sender); + } + } + + function emergencyWithdrawMdxAndToken(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + uint256 beforeToken = IERC20(multLpToken).balanceOf(address(this)); + IMasterChefBSC(multLpChef).withdraw(poolCorrespond[_pid], amount); + uint256 afterToken = IERC20(multLpToken).balanceOf(address(this)); + pool.accMultLpPerShare = pool.accMultLpPerShare.add(afterToken.sub(beforeToken).mul(1e12).div(pool.totalAmount)); + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + function emergencyWithdrawMdx(uint256 _pid, address _user) private { + PoolInfo storage pool = poolInfo[_pid]; + UserInfo storage user = userInfo[_pid][_user]; + uint256 amount = user.amount; + user.amount = 0; + user.rewardDebt = 0; + pool.lpToken.safeTransfer(_user, amount); + pool.totalAmount = pool.totalAmount.sub(amount); + emit EmergencyWithdraw(_user, _pid, amount); + } + + // Safe MDX transfer function, just in case if rounding error causes pool to not have enough MDXs. + function safeMdxTransfer(address _to, uint256 _amount) internal { + uint256 mdxBal = mdx.balanceOf(address(this)); + if (_amount > mdxBal) { + mdx.transfer(_to, mdxBal); + } else { + mdx.transfer(_to, _amount); + } + } + + modifier notPause() { + require(paused == false, "Mining has been suspended"); + _; + } +} diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..c6cd65c4bb7 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = false; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..17d4a48803e --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/CCD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/CCD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..7b8b75a82e7 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/CCD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1170 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..d19d710d9ff --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (true) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..8dd80028b03 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/ECS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/ECS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..195491df3c0 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/ECS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint8(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..a2a24cd71b8 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + /* emit OwnershipTransferred(address(0), msgSender); */ + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..22196c586af --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/ETR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/ETR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..072f14f8e36 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/ETR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.delegatecall(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..29280254409 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/GVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/GVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..6474c4f0a00 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/GVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = block.difficulty + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..aef7880f7f2 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..3f4220858c0 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual onlyOwner { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..3c425cb3f38 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..129787f134b --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..d0dac1f8746 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1172 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/PKD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/PKD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..e37f49600c5 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/PKD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..231af5c2e36 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..12fea1b4a64 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..12fea1b4a64 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/SKI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/SKI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..c7598cb8e2d --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/SKI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = super.balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..d782ea0c7e2 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/TOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/TOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..36c51c83264 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/TOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return tx.origin; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..9882cd24315 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..ad1bdeaffa2 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/1/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address public _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..56706a2f914 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = false; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = true; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = false; + _; + inSwapAndLiquify = true; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = false; + _isExcludedFromFee[address(this)] = false; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return false; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return false; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return false; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return false; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..3f5e96475cf --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a + b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a <= 0) { + return 0; + } + + uint256 c = a + b; + require(c + a <= b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b >= 0, errorMessage); + uint256 c = a + b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..19aad71c07f --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1158 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (true) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (true) { + return returndata; + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (true) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (true) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (true) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (true) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(true) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(true) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..ff8a553fcd9 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes storage) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes storage data) internal returns (bytes storage) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes storage data, string storage errorMessage) internal returns (bytes storage) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes storage data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..9e0c351602f --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + /* emit OwnershipTransferred(address(0), msgSender); */ + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + /* emit OwnershipTransferred(_owner, address(0)); */ + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + /* emit OwnershipTransferred(_owner, newOwner); */ + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + /* emit OwnershipTransferred(_owner, address(0)); */ + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + /* emit OwnershipTransferred(_owner, _previousOwner); */ + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + /* emit Transfer(address(0), tokenOwner, _tTotal); */ + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + /* emit Transfer(sender, recipient, tTransferAmount); */ + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + /* emit SwapAndLiquifyEnabledUpdated(_enabled); */ + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + /* emit SwapAndLiquify(half, newBalance, otherHalf); */ + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..3178032e32f --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b > 0, errorMessage); */ + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b != 0, errorMessage); */ + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + /* require(address(this).balance >= amount, "Address: insufficient balance"); */ + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + /* require(success, "Address: unable to send value, recipient may have reverted"); */ + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + /* require(address(this).balance >= value, "Address: insufficient balance for call"); */ + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + /* require(isContract(target), "Address: call to non-contract"); */ + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + /* revert(errorMessage); */ + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..ad37aecd0e1 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) public pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) public pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) public pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) public view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) public { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..eccd6a57e3b --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 1, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 1, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 1) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(1), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(1)); + _owner = address(1); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(1), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..35e04418f02 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual onlyOwner { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override lockTheSwap returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual lockTheSwap returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual lockTheSwap returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public lockTheSwap { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private lockTheSwap { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private lockTheSwap { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private lockTheSwap { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..92b94df4501 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1159 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..e8b34c279b9 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + /* return 0; */ + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + /* return c; */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + /* return div(a, b, "SafeMath: division by zero"); */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + /* return c; */ + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + /* return mod(a, b, "SafeMath: modulo by zero"); */ + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + /* return a % b; */ + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + /* return msg.sender; */ + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..6b936c54a84 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint liquidity, uint amountToken, uint amountETH); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountB, uint amountA); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH, uint amountToken); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountB, uint amountA); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH, uint amountToken); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (tLiquidity, rAmount, rTransferAmount, rFee, tTransferAmount, tFee); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tLiquidity, tTransferAmount, tFee); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..6b936c54a84 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint liquidity, uint amountToken, uint amountETH); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountB, uint amountA); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH, uint amountToken); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountB, uint amountA); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH, uint amountToken); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (tLiquidity, rAmount, rTransferAmount, rFee, tTransferAmount, tFee); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tLiquidity, tTransferAmount, tFee); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..642cbcf0bae --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require( _isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if ( deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i--) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if( takeFee) + removeAllFee(); + + if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if ( _isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if ( _isExcluded[sender] && _isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..b666adf5c9f --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/10/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address public _owner; + address public _previousOwner; + uint256 public _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address public dead = 0x000000000000000000000000000000000000dEaD; + uint256 internal maxLiqFee = 10; + uint256 internal maxTaxFee = 10; + uint256 internal minMxTxPercentage = 50; + uint256 internal prevLiqFee; + uint256 internal prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] public _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..73d94249250 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = false; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = true; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..5cfb565d27e --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/CCD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/CCD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..85fbc12a539 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/CCD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1140 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..e077abe4e07 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (true) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (true) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..c9d29d3ff5a --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..32d04040962 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + /* emit OwnershipTransferred(address(0), msgSender); */ + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + /* emit OwnershipTransferred(_owner, address(0)); */ + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..fa663b07edc --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/ETR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/ETR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..d53114af926 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/ETR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.delegatecall(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.delegatecall(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..9f0f3fe7ff8 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/GVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/GVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..9cfce6cb050 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/GVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = block.difficulty + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(block.difficulty > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..308f83fc50e --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..ccf7ce71fff --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual onlyOwner { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..c84c360fe93 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..1b3d539a971 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..492643d4ee6 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1168 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + + + + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/PKD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/PKD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..4fbcfd12903 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/PKD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..15a79336bf5 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..924a57fdd2f --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..924a57fdd2f --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..46cf93ee366 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, ""); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/TOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/TOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..82ae2309673 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/TOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return tx.origin; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == tx.origin, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..f4e53095a54 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require( _isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..a6e3c5c5bbe --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/2/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address public _owner; + address public _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..7558783c7e9 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = false; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = true; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = false; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..c430d85e364 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..bc1f0573242 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1161 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (true) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (true) { + return returndata; + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..dc1968b8966 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..b124a13eb2b --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + /* emit OwnershipTransferred(address(0), msgSender); */ + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + /* emit OwnershipTransferred(_owner, address(0)); */ + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + /* emit OwnershipTransferred(_owner, newOwner); */ + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..7a139e9e184 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..a07302f83ad --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/GVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/GVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..41f0a97e585 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/GVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = block.difficulty + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(block.difficulty > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.number + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..66f7125cf35 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..2159b78c5a3 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual onlyOwner { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override lockTheSwap returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..1be4e0caed5 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external lockTheSwap { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..868b683420d --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..436ed0e7213 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1165 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + + + + + + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/PKD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/PKD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..cdc1901613c --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/PKD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..74b1fee56ab --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..0d71ea5ebd9 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..0d71ea5ebd9 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..2c11249d8ff --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, ""); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, ""); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..d29968df2d1 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require( _isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if ( deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..e5ebb4c6ab8 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/3/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address public _owner; + address public _previousOwner; + uint256 public _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..fe82c6aae4f --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = false; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = true; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = false; + _; + inSwapAndLiquify = true; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..f5e7c514046 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a + b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..db9929c7b03 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1161 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (true) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (true) { + return returndata; + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (true) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..aeaafb03577 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes storage) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..23bef3ae190 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + /* emit OwnershipTransferred(address(0), msgSender); */ + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + /* emit OwnershipTransferred(_owner, address(0)); */ + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + /* emit OwnershipTransferred(_owner, newOwner); */ + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + /* emit OwnershipTransferred(_owner, address(0)); */ + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..40171ae9f13 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b > 0, errorMessage); */ + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..d7b92ccce7a --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) public pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/GVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/GVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..85fe3e7cf04 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/GVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = block.difficulty + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(block.difficulty > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.number + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.number + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..1b15f0844c8 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 1, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..dc54811621c --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual onlyOwner { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override lockTheSwap returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..95dfd9a54d0 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external lockTheSwap { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external lockTheSwap { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..9c26a9618d0 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..f495f920ca5 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1163 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + + + + + + + + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/PKD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/PKD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..9ddaa7c9e4b --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/PKD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + function swapExactETHForTokensSupportingFeeOnTransferTokens( + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external ; + function swapExactTokensForETHSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..39954ad88db --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + /* return 0; */ + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..31eaac3f500 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint liquidity, uint amountToken, uint amountETH); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..31eaac3f500 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint liquidity, uint amountToken, uint amountETH); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..9ef3b5c9a09 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, ""); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, ""); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, ""); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..06a2943522a --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require( _isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if ( deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i--) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..b8fd2431418 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/4/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address public _owner; + address public _previousOwner; + uint256 public _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address public dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..98f0a86ff4b --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = false; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = true; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = false; + _; + inSwapAndLiquify = true; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = false; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..324dd612f2e --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a + b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a <= 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..5f504fed24c --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1161 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (true) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (true) { + return returndata; + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (true) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (true) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..b5640fbf5c9 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes storage) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes storage data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..8fdf06e3109 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + /* emit OwnershipTransferred(address(0), msgSender); */ + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + /* emit OwnershipTransferred(_owner, address(0)); */ + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + /* emit OwnershipTransferred(_owner, newOwner); */ + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + /* emit OwnershipTransferred(_owner, address(0)); */ + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + /* emit OwnershipTransferred(_owner, _previousOwner); */ + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..356ae693a0c --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b > 0, errorMessage); */ + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b != 0, errorMessage); */ + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..006e78fef1a --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) public pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) public pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..ec2b8bfdc13 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 1, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 1, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..590a12c8f42 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual onlyOwner { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override lockTheSwap returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual lockTheSwap returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..953220eac21 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external lockTheSwap { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external lockTheSwap { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external lockTheSwap { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..2ade6f25da0 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..207e7fe6a26 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1160 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + + + + + + + + + + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..7584692f7b6 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + /* return 0; */ + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + /* return c; */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..4acb5534da7 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint liquidity, uint amountToken, uint amountETH); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountB, uint amountA); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..4acb5534da7 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint liquidity, uint amountToken, uint amountETH); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountB, uint amountA); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..0bcdf922dcc --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, ""); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, ""); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, ""); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, ""); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..5f78053e084 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require( _isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if ( deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i--) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..44f8d5dd393 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/5/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address public _owner; + address public _previousOwner; + uint256 public _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address public dead = 0x000000000000000000000000000000000000dEaD; + uint256 internal maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..1234b6c4d73 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = false; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = true; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = false; + _; + inSwapAndLiquify = true; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = false; + _isExcludedFromFee[address(this)] = false; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..397a89d5e78 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a + b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a <= 0) { + return 0; + } + + uint256 c = a + b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..9564498eb25 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1158 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (true) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (true) { + return returndata; + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (true) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (true) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..aced6a907a8 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes storage) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes storage data) internal returns (bytes storage) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..c1bc26c1c85 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + /* emit OwnershipTransferred(address(0), msgSender); */ + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + /* emit OwnershipTransferred(_owner, address(0)); */ + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + /* emit OwnershipTransferred(_owner, newOwner); */ + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + /* emit OwnershipTransferred(_owner, address(0)); */ + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + /* emit OwnershipTransferred(_owner, _previousOwner); */ + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + /* emit Transfer(address(0), tokenOwner, _tTotal); */ + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..c64ad0234fc --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b > 0, errorMessage); */ + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b != 0, errorMessage); */ + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + /* require(address(this).balance >= amount, "Address: insufficient balance"); */ + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..73dda09c486 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) public pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) public pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..963e80dd54d --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 1, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 1, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 1) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..448fc13b9ca --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual onlyOwner { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override lockTheSwap returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual lockTheSwap returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual lockTheSwap returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..8cfe581d9a3 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external lockTheSwap { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external lockTheSwap { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external lockTheSwap { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner() { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..ad105c3c0fa --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..c5134d4ddc0 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/ORFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1156 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + + + + + + + + + + + + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..3764c412c74 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + /* return 0; */ + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + /* return c; */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + /* return div(a, b, "SafeMath: division by zero"); */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..70b0f7b9091 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint liquidity, uint amountToken, uint amountETH); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountB, uint amountA); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH, uint amountToken); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..70b0f7b9091 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint liquidity, uint amountToken, uint amountETH); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountB, uint amountA); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH, uint amountToken); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..0cdc754de0c --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, ""); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, ""); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, ""); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, ""); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..b050ad66810 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require( _isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if ( deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i--) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if( takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..f607ea5f94f --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/6/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address public _owner; + address public _previousOwner; + uint256 public _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address public dead = 0x000000000000000000000000000000000000dEaD; + uint256 internal maxLiqFee = 10; + uint256 internal maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..b187082c6bb --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = false; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = true; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = false; + _; + inSwapAndLiquify = true; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = false; + _isExcludedFromFee[address(this)] = false; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return false; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..f8824079096 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a + b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a <= 0) { + return 0; + } + + uint256 c = a + b; + require(c + a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..7d5266c7027 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1158 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (true) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (true) { + return returndata; + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (true) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (true) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (true) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..123f5f0ab22 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes storage) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes storage data) internal returns (bytes storage) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes storage data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..23e3aec5893 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + /* emit OwnershipTransferred(address(0), msgSender); */ + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + /* emit OwnershipTransferred(_owner, address(0)); */ + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + /* emit OwnershipTransferred(_owner, newOwner); */ + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + /* emit OwnershipTransferred(_owner, address(0)); */ + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + /* emit OwnershipTransferred(_owner, _previousOwner); */ + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + /* emit Transfer(address(0), tokenOwner, _tTotal); */ + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + /* emit Transfer(sender, recipient, tTransferAmount); */ + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..0fe62100a57 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b > 0, errorMessage); */ + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b != 0, errorMessage); */ + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + /* require(address(this).balance >= amount, "Address: insufficient balance"); */ + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + /* require(success, "Address: unable to send value, recipient may have reverted"); */ + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..7ba6e3675af --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) public pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) public pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) public pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..36f7bb5e8cb --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 1, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 1, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 1) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(1), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..c5f7eb93911 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual onlyOwner { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override lockTheSwap returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual lockTheSwap returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual lockTheSwap returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public lockTheSwap { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..4ad9107aa0a --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external lockTheSwap { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external lockTheSwap { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external lockTheSwap { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner() { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private onlyOwner() { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..5a806d5ec37 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1172 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..5701083ac37 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + /* return 0; */ + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + /* return c; */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + /* return div(a, b, "SafeMath: division by zero"); */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + /* return c; */ + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..1b15dd9523d --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint liquidity, uint amountToken, uint amountETH); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountB, uint amountA); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH, uint amountToken); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountB, uint amountA); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..1b15dd9523d --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint liquidity, uint amountToken, uint amountETH); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountB, uint amountA); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH, uint amountToken); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountB, uint amountA); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..3a0b49302b6 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/SLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, ""); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, ""); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, ""); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, ""); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..d829dd95ae7 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require( _isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if ( deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i--) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if( takeFee) + removeAllFee(); + + if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..2e18d5d5d21 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/7/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address public _owner; + address public _previousOwner; + uint256 public _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address public dead = 0x000000000000000000000000000000000000dEaD; + uint256 internal maxLiqFee = 10; + uint256 internal maxTaxFee = 10; + uint256 internal minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..68429a307b5 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = false; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = true; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = false; + _; + inSwapAndLiquify = true; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = false; + _isExcludedFromFee[address(this)] = false; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return false; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return false; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..6f76c161fce --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a + b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a <= 0) { + return 0; + } + + uint256 c = a + b; + require(c + a <= b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..66cc38fa360 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1158 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (true) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (true) { + return returndata; + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (true) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (true) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (true) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (true) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..b1d3d0597c5 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes storage) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes storage data) internal returns (bytes storage) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes storage data, string storage errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..e7c0129b6c1 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + /* emit OwnershipTransferred(address(0), msgSender); */ + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + /* emit OwnershipTransferred(_owner, address(0)); */ + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + /* emit OwnershipTransferred(_owner, newOwner); */ + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + /* emit OwnershipTransferred(_owner, address(0)); */ + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + /* emit OwnershipTransferred(_owner, _previousOwner); */ + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + /* emit Transfer(address(0), tokenOwner, _tTotal); */ + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + /* emit Transfer(sender, recipient, tTransferAmount); */ + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + /* emit SwapAndLiquifyEnabledUpdated(_enabled); */ + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..a16cf9b7a04 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b > 0, errorMessage); */ + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b != 0, errorMessage); */ + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + /* require(address(this).balance >= amount, "Address: insufficient balance"); */ + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + /* require(success, "Address: unable to send value, recipient may have reverted"); */ + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + /* require(address(this).balance >= value, "Address: insufficient balance for call"); */ + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..9fc1730c8dd --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) public pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) public pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) public pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..319b41f7642 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 1, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 1, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 1) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(1), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(1)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..ded5e02d7fc --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual onlyOwner { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override lockTheSwap returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual lockTheSwap returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual lockTheSwap returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public lockTheSwap { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private lockTheSwap { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..b31f78af1ca --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external lockTheSwap { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external lockTheSwap { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external lockTheSwap { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner() { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private onlyOwner() { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner() { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..6706d2841b4 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1167 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..114be890f3f --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + /* return 0; */ + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + /* return c; */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + /* return div(a, b, "SafeMath: division by zero"); */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + /* return c; */ + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + /* return mod(a, b, "SafeMath: modulo by zero"); */ + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..582facc0c25 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint liquidity, uint amountToken, uint amountETH); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountB, uint amountA); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH, uint amountToken); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountB, uint amountA); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH, uint amountToken); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..582facc0c25 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint liquidity, uint amountToken, uint amountETH); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountB, uint amountA); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH, uint amountToken); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountB, uint amountA); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH, uint amountToken); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..687e512760d --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require( _isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if ( deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i--) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if( takeFee) + removeAllFee(); + + if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if ( _isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..fe919f0a16d --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/8/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address public _owner; + address public _previousOwner; + uint256 public _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address public dead = 0x000000000000000000000000000000000000dEaD; + uint256 internal maxLiqFee = 10; + uint256 internal maxTaxFee = 10; + uint256 internal minMxTxPercentage = 50; + uint256 internal prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..1bd94ac42e8 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/BLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = false; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = true; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = false; + _; + inSwapAndLiquify = true; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = false; + _isExcludedFromFee[address(this)] = false; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return false; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return false; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return false; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..408214040bb --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/BOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a + b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a <= 0) { + return 0; + } + + uint256 c = a + b; + require(c + a <= b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b >= 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..47c683a93fc --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/CSC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1158 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (true) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (true) { + return returndata; + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (true) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (true) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (true) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (true) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(true) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..15420e018f5 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/DLR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string storage errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes storage) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes storage data) internal returns (bytes storage) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes storage data, string storage errorMessage) internal returns (bytes storage) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..476075bb706 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/EED/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + /* emit OwnershipTransferred(address(0), msgSender); */ + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + /* emit OwnershipTransferred(_owner, address(0)); */ + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + /* emit OwnershipTransferred(_owner, newOwner); */ + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + /* emit OwnershipTransferred(_owner, address(0)); */ + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + /* emit OwnershipTransferred(_owner, _previousOwner); */ + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + /* emit Transfer(address(0), tokenOwner, _tTotal); */ + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + /* emit Transfer(sender, recipient, tTransferAmount); */ + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + /* emit SwapAndLiquifyEnabledUpdated(_enabled); */ + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..786a8ff5b2f --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/EHC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b > 0, errorMessage); */ + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + /* require(b != 0, errorMessage); */ + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + /* require(address(this).balance >= amount, "Address: insufficient balance"); */ + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + /* require(success, "Address: unable to send value, recipient may have reverted"); */ + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + /* require(address(this).balance >= value, "Address: insufficient balance for call"); */ + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + /* require(isContract(target), "Address: call to non-contract"); */ + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..9adf6acc720 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/FVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) public pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) public pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) public pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) public pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) public view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..cf84ae6aff1 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/ILR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 1, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 1, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 1) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(1), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(1)); + _owner = address(1); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..d26f1f36bb6 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/MOI/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual onlyOwner { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override lockTheSwap returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override lockTheSwap returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual lockTheSwap returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual lockTheSwap returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public lockTheSwap { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private lockTheSwap { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private lockTheSwap { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..86714ec8cb4 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/MOR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner() { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external lockTheSwap { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external lockTheSwap { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external lockTheSwap { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner() { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private onlyOwner() { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner() { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner() { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..3aab7b21a41 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/OLFD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1165 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..a8f6102b8db --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/RSD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + /* return 0; */ + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + /* return c; */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + /* return div(a, b, "SafeMath: division by zero"); */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + /* return c; */ + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + /* return mod(a, b, "SafeMath: modulo by zero"); */ + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + /* return a % b; */ + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..ed7f8ba0db9 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/RVS/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint liquidity, uint amountToken, uint amountETH); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountB, uint amountA); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH, uint amountToken); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountB, uint amountA); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH, uint amountToken); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (tLiquidity, rAmount, rTransferAmount, rFee, tTransferAmount, tFee); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..ed7f8ba0db9 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/SCEC/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint32 blockTimestampLast, uint112 reserve0, uint112 reserve1); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount1, uint amount0); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint liquidity, uint amountA, uint amountB); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint liquidity, uint amountToken, uint amountETH); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountB, uint amountA); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH, uint amountToken); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountB, uint amountA); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH, uint amountToken); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (tLiquidity, rAmount, rTransferAmount, rFee, tTransferAmount, tFee); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..86967235bca --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/UORD/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require( _isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if ( deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i--) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if( takeFee) + removeAllFee(); + + if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if ( _isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if ( _isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..0fd865f177a --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/9/VVR/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address public _owner; + address public _previousOwner; + uint256 public _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address public dead = 0x000000000000000000000000000000000000dEaD; + uint256 internal maxLiqFee = 10; + uint256 internal maxTaxFee = 10; + uint256 internal minMxTxPercentage = 50; + uint256 internal prevLiqFee; + uint256 internal prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/original/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/original/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol new file mode 100644 index 00000000000..3f84efd09e3 --- /dev/null +++ b/contracts/mutants/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0/original/BSCSCAN-0xC512261b8AE70260447A74aC7d94dAee150B90C0.sol @@ -0,0 +1,1174 @@ +/** + *Submitted for verification at BscScan.com on 2021-07-13 +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; +pragma experimental ABIEncoderV2; + +interface IERC20 { + + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ + +library SafeMath { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +abstract contract Context { + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} + + +/** + * @dev Collection of functions related to the address type + */ +library Address { + /** + * @dev Returns true if `account` is a contract. + * + * [IMPORTANT] + * ==== + * It is unsafe to assume that an address for which this function returns + * false is an externally-owned account (EOA) and not a contract. + * + * Among others, `isContract` will return false for the following + * types of addresses: + * + * - an externally-owned account + * - a contract in construction + * - an address where a contract will be created + * - an address where a contract lived, but was destroyed + * ==== + */ + function isContract(address account) internal view returns (bool) { + // According to EIP-1052, 0x0 is the value returned for not-yet created accounts + // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned + // for accounts without code, i.e. `keccak256('')` + bytes32 codehash; + bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + // solhint-disable-next-line no-inline-assembly + assembly { codehash := extcodehash(account) } + return (codehash != accountHash && codehash != 0x0); + } + + /** + * @dev Replacement for Solidity's `transfer`: sends `amount` wei to + * `recipient`, forwarding all available gas and reverting on errors. + * + * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost + * of certain opcodes, possibly making contracts go over the 2300 gas limit + * imposed by `transfer`, making them unable to receive funds via + * `transfer`. {sendValue} removes this limitation. + * + * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * + * IMPORTANT: because control is transferred to `recipient`, care must be + * taken to not create reentrancy vulnerabilities. Consider using + * {ReentrancyGuard} or the + * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + */ + function sendValue(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Address: insufficient balance"); + + // solhint-disable-next-line avoid-low-level-calls, avoid-call-value + (bool success, ) = recipient.call{ value: amount }(""); + require(success, "Address: unable to send value, recipient may have reverted"); + } + + /** + * @dev Performs a Solidity function call using a low level `call`. A + * plain`call` is an unsafe replacement for a function call: use this + * function instead. + * + * If `target` reverts with a revert reason, it is bubbled up by this + * function (like regular Solidity function calls). + * + * Returns the raw returned data. To convert to the expected return value, + * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. + * + * Requirements: + * + * - `target` must be a contract. + * - calling `target` with `data` must not revert. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data) internal returns (bytes memory) { + return functionCall(target, data, "Address: low-level call failed"); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with + * `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + return _functionCallWithValue(target, data, 0, errorMessage); + } + + /** + * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], + * but also transferring `value` wei to `target`. + * + * Requirements: + * + * - the calling contract must have an ETH balance of at least `value`. + * - the called Solidity function must be `payable`. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { + return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); + } + + /** + * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but + * with `errorMessage` as a fallback revert reason when `target` reverts. + * + * _Available since v3.1._ + */ + function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + require(address(this).balance >= value, "Address: insufficient balance for call"); + return _functionCallWithValue(target, data, value, errorMessage); + } + + function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { + require(isContract(target), "Address: call to non-contract"); + + // solhint-disable-next-line avoid-low-level-calls + (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); + if (success) { + return returndata; + } else { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } + } +} + +/** + * @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. + * + * By default, the owner account will be the one that deploys the contract. 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 is Context { + address private _owner; + address private _previousOwner; + uint256 private _lockTime; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /** + * @dev Initializes the contract setting the deployer as the initial owner. + */ + constructor () internal { + address msgSender = _msgSender(); + _owner = msgSender; + emit OwnershipTransferred(address(0), msgSender); + } + + /** + * @dev Returns the address of the current owner. + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(_owner == _msgSender(), "Ownable: caller is not the owner"); + _; + } + + /** + * @dev Leaves the contract without owner. It will not be possible to call + * `onlyOwner` functions anymore. Can only be called by the current owner. + * + * NOTE: Renouncing ownership will leave the contract without an owner, + * thereby removing any functionality that is only available to the owner. + */ + function renounceOwnership() public virtual onlyOwner { + emit OwnershipTransferred(_owner, address(0)); + _owner = address(0); + } + + /** + * @dev Transfers ownership of the contract to a new account (`newOwner`). + * Can only be called by the current owner. + */ + function transferOwnership(address newOwner) public virtual onlyOwner { + require(newOwner != address(0), "Ownable: new owner is the zero address"); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } + + function geUnlockTime() public view returns (uint256) { + return _lockTime; + } + + //Locks the contract for owner for the amount of time provided + function lock(uint256 time) public virtual onlyOwner { + _previousOwner = _owner; + _owner = address(0); + _lockTime = now + time; + emit OwnershipTransferred(_owner, address(0)); + } + + //Unlocks the contract for owner when _lockTime is exceeds + function unlock() public virtual { + require(_previousOwner == msg.sender, "You don't have permission to unlock the token contract"); + // SWC-123-Requirement Violation: L467 + require(now > _lockTime , "Contract is locked until 7 days"); + emit OwnershipTransferred(_owner, _previousOwner); + _owner = _previousOwner; + } +} + +// pragma solidity >=0.5.0; + +interface IUniswapV2Factory { + event PairCreated(address indexed token0, address indexed token1, address pair, uint); + + function feeTo() external view returns (address); + function feeToSetter() external view returns (address); + + function getPair(address tokenA, address tokenB) external view returns (address pair); + function allPairs(uint) external view returns (address pair); + function allPairsLength() external view returns (uint); + + function createPair(address tokenA, address tokenB) external returns (address pair); + + function setFeeTo(address) external; + function setFeeToSetter(address) external; +} + + +// pragma solidity >=0.5.0; + +interface IUniswapV2Pair { + event Approval(address indexed owner, address indexed spender, uint value); + event Transfer(address indexed from, address indexed to, uint value); + + function name() external pure returns (string memory); + function symbol() external pure returns (string memory); + function decimals() external pure returns (uint8); + function totalSupply() external view returns (uint); + function balanceOf(address owner) external view returns (uint); + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint value) external returns (bool); + function transfer(address to, uint value) external returns (bool); + function transferFrom(address from, address to, uint value) external returns (bool); + + function DOMAIN_SEPARATOR() external view returns (bytes32); + function PERMIT_TYPEHASH() external pure returns (bytes32); + function nonces(address owner) external view returns (uint); + + function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; + + event Mint(address indexed sender, uint amount0, uint amount1); + event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); + event Swap( + address indexed sender, + uint amount0In, + uint amount1In, + uint amount0Out, + uint amount1Out, + address indexed to + ); + event Sync(uint112 reserve0, uint112 reserve1); + + function MINIMUM_LIQUIDITY() external pure returns (uint); + function factory() external view returns (address); + function token0() external view returns (address); + function token1() external view returns (address); + function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); + function price0CumulativeLast() external view returns (uint); + function price1CumulativeLast() external view returns (uint); + function kLast() external view returns (uint); + + function mint(address to) external returns (uint liquidity); + function burn(address to) external returns (uint amount0, uint amount1); + function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; + function skim(address to) external; + function sync() external; + + function initialize(address, address) external; +} + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router01 { + function factory() external pure returns (address); + function WETH() external pure returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint amountADesired, + uint amountBDesired, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB, uint liquidity); + function addLiquidityETH( + address token, + uint amountTokenDesired, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external payable returns (uint amountToken, uint amountETH, uint liquidity); + function removeLiquidity( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline + ) external returns (uint amountA, uint amountB); + function removeLiquidityETH( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountToken, uint amountETH); + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint liquidity, + uint amountAMin, + uint amountBMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountA, uint amountB); + function removeLiquidityETHWithPermit( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountToken, uint amountETH); + function swapExactTokensForTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapTokensForExactTokens( + uint amountOut, + uint amountInMax, + address[] calldata path, + address to, + uint deadline + ) external returns (uint[] memory amounts); + function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) + external + returns (uint[] memory amounts); + function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) + external + payable + returns (uint[] memory amounts); + + function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); + function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); + function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); + function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); + function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); +} + + + +// pragma solidity >=0.6.2; + +interface IUniswapV2Router02 is IUniswapV2Router01 { + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline + ) external returns (uint amountETH); + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint liquidity, + uint amountTokenMin, + uint amountETHMin, + address to, + uint deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s + ) external returns (uint amountETH); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint amountIn, + uint amountOutMin, + address[] calldata path, + address to, + uint deadline + ) external; + 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; +} + + +contract LiquidityGeneratorToken is Context, IERC20, Ownable { + using SafeMath for uint256; + using Address for address; + address dead = 0x000000000000000000000000000000000000dEaD; + uint256 public maxLiqFee = 10; + uint256 public maxTaxFee = 10; + uint256 public minMxTxPercentage = 50; + uint256 public prevLiqFee; + uint256 public prevTaxFee; + mapping (address => uint256) private _rOwned; + mapping (address => uint256) private _tOwned; + mapping (address => mapping (address => uint256)) private _allowances; + + mapping (address => bool) private _isExcludedFromFee; + // SWC-135-Code With No Effects: L702 - L703 + mapping (address => bool) private _isExcluded; + address[] private _excluded; + address public router = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PCS v2 mainnet + uint256 private constant MAX = ~uint256(0); + uint256 public _tTotal; + uint256 private _rTotal; + uint256 private _tFeeTotal; + // SWC-131-Presence of unused variables: L710 + bool public mintedByDxsale = true; + string public _name; + string public _symbol; + uint8 private _decimals; + + uint256 public _taxFee; + uint256 private _previousTaxFee = _taxFee; + + uint256 public _liquidityFee; + uint256 private _previousLiquidityFee = _liquidityFee; + + IUniswapV2Router02 public immutable uniswapV2Router; + address public immutable uniswapV2Pair; + + bool inSwapAndLiquify; + bool public swapAndLiquifyEnabled = false; + + uint256 public _maxTxAmount; + uint256 public numTokensSellToAddToLiquidity; + + event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); + event SwapAndLiquifyEnabledUpdated(bool enabled); + event SwapAndLiquify( + uint256 tokensSwapped, + uint256 ethReceived, + uint256 tokensIntoLiqudity + ); + + modifier lockTheSwap { + inSwapAndLiquify = true; + _; + inSwapAndLiquify = false; + } + + constructor (address tokenOwner,string memory name, string memory symbol,uint8 decimal, uint256 amountOfTokenWei,uint8 setTaxFee, uint8 setLiqFee, uint256 _maxTaxFee, uint256 _maxLiqFee, uint256 _minMxTxPer) public { + _name = name; + _symbol = symbol; + _decimals = decimal; + _tTotal = amountOfTokenWei; + _rTotal = (MAX - (MAX % _tTotal)); + + _rOwned[tokenOwner] = _rTotal; + + maxTaxFee = _maxTaxFee; + maxLiqFee = _maxLiqFee; + minMxTxPercentage = _minMxTxPer; + prevTaxFee = setTaxFee; + prevLiqFee = setLiqFee; + + _maxTxAmount = amountOfTokenWei; + numTokensSellToAddToLiquidity = amountOfTokenWei.mul(1).div(1000); + IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(router); + // Create a uniswap pair for this new token + uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) + .createPair(address(this), _uniswapV2Router.WETH()); + + // set the rest of the contract variables + uniswapV2Router = _uniswapV2Router; + + //exclude owner and this contract from fee + _isExcludedFromFee[owner()] = true; + _isExcludedFromFee[address(this)] = true; + + emit Transfer(address(0), tokenOwner, _tTotal); + } + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns (uint8) { + return _decimals; + } + + function totalSupply() public view override returns (uint256) { + return _tTotal; + } + + function balanceOf(address account) public view override returns (uint256) { + // SWC-135-Code With No Effects: L793 - L794 + if (_isExcluded[account]) return _tOwned[account]; + return tokenFromReflection(_rOwned[account]); + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + _transfer(sender, recipient, amount); + _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); + return true; + } + + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); + return true; + } + + // SWC-135-Code With No Effects: L828 - L831 + function isExcludedFromReward(address account) public view returns (bool) { + return _isExcluded[account]; + } + + function totalFees() public view returns (uint256) { + return _tFeeTotal; + } + + // SWC-135-Code With No Effects: L837 - L844 + function deliver(uint256 tAmount) public { + address sender = _msgSender(); + require(!_isExcluded[sender], "Excluded addresses cannot call this function"); + (uint256 rAmount,,,,,) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rTotal = _rTotal.sub(rAmount); + _tFeeTotal = _tFeeTotal.add(tAmount); + } + + function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { + require(tAmount <= _tTotal, "Amount must be less than supply"); + if (!deductTransferFee) { + (uint256 rAmount,,,,,) = _getValues(tAmount); + return rAmount; + } else { + (,uint256 rTransferAmount,,,,) = _getValues(tAmount); + return rTransferAmount; + } + } + + function tokenFromReflection(uint256 rAmount) public view returns(uint256) { + require(rAmount <= _rTotal, "Amount must be less than total reflections"); + uint256 currentRate = _getRate(); + return rAmount.div(currentRate); + } + + + // SWC-135-Code With No Effects: L865 - L874 + function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function excludeFromFee(address account) public onlyOwner { + _isExcludedFromFee[account] = true; + } + + function includeInFee(address account) public onlyOwner { + _isExcludedFromFee[account] = false; + } + + function setTaxFeePercent(uint256 taxFee) external onlyOwner() { + require(taxFee >= 0 && taxFee <=maxTaxFee,"taxFee out of range"); + _taxFee = taxFee; + } + + function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { + require(liquidityFee >= 0 && liquidityFee <=maxLiqFee,"liquidityFee out of range"); + _liquidityFee = liquidityFee; + } + + function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { + require(maxTxPercent >= minMxTxPercentage && maxTxPercent <=100,"maxTxPercent out of range"); + _maxTxAmount = _tTotal.mul(maxTxPercent).div( + 10**2 + ); + } + + function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { + swapAndLiquifyEnabled = _enabled; + emit SwapAndLiquifyEnabledUpdated(_enabled); + } + + //to recieve ETH from uniswapV2Router when swaping + receive() external payable {} + + function _reflectFee(uint256 rFee, uint256 tFee) private { + _rTotal = _rTotal.sub(rFee); + _tFeeTotal = _tFeeTotal.add(tFee); + } + + function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { + (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); + return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); + } + + function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { + uint256 tFee = calculateTaxFee(tAmount); + uint256 tLiquidity = calculateLiquidityFee(tAmount); + uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); + return (tTransferAmount, tFee, tLiquidity); + } + + function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { + uint256 rAmount = tAmount.mul(currentRate); + uint256 rFee = tFee.mul(currentRate); + uint256 rLiquidity = tLiquidity.mul(currentRate); + uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); + return (rAmount, rTransferAmount, rFee); + } + + function _getRate() private view returns(uint256) { + (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); + return rSupply.div(tSupply); + } + + // SWC-135-Code With No Effects: L941 - L951 + function _getCurrentSupply() private view returns(uint256, uint256) { + uint256 rSupply = _rTotal; + uint256 tSupply = _tTotal; + for (uint256 i = 0; i < _excluded.length; i++) { + if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); + rSupply = rSupply.sub(_rOwned[_excluded[i]]); + tSupply = tSupply.sub(_tOwned[_excluded[i]]); + } + if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); + return (rSupply, tSupply); + } + + // SWC-135-Code With No Effects: L952 - L958 + function _takeLiquidity(uint256 tLiquidity) private { + uint256 currentRate = _getRate(); + uint256 rLiquidity = tLiquidity.mul(currentRate); + _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); + if(_isExcluded[address(this)]) + _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); + } + + function calculateTaxFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_taxFee).div( + 10**2 + ); + } + + function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { + return _amount.mul(_liquidityFee).div( + 10**2 + ); + } + + function removeAllFee() private { + if(_taxFee == 0 && _liquidityFee == 0) return; + + _previousTaxFee = _taxFee; + _previousLiquidityFee = _liquidityFee; + + _taxFee = 0; + _liquidityFee = 0; + } + + function restoreAllFee() private { + _taxFee = _previousTaxFee; + _liquidityFee = _previousLiquidityFee; + } + + function isExcludedFromFee(address account) public view returns(bool) { + return _isExcludedFromFee[account]; + } + + 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 _transfer( + address from, + address to, + uint256 amount + ) private { + require(from != address(0), "ERC20: transfer from the zero address"); + require(to != address(0), "ERC20: transfer to the zero address"); + require(amount > 0, "Transfer amount must be greater than zero"); + if(from != owner() && to != owner()) + require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); + + // is the token balance of this contract address over the min number of + // tokens that we need to initiate a swap + liquidity lock? + // also, don't get caught in a circular liquidity event. + // also, don't swap & liquify if sender is uniswap pair. + uint256 contractTokenBalance = balanceOf(address(this)); + + if(contractTokenBalance >= _maxTxAmount) + { + contractTokenBalance = _maxTxAmount; + } + + bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; + if ( + overMinTokenBalance && + !inSwapAndLiquify && + from != uniswapV2Pair && + swapAndLiquifyEnabled + ) { + contractTokenBalance = numTokensSellToAddToLiquidity; + //add liquidity + swapAndLiquify(contractTokenBalance); + } + + //indicates if fee should be deducted from transfer + bool takeFee = true; + + //if any account belongs to _isExcludedFromFee account then remove the fee + if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ + takeFee = false; + } + + //transfer amount, it will take tax, burn, liquidity fee + _tokenTransfer(from,to,amount,takeFee); + } + + function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { + // split the contract balance into halves + uint256 half = contractTokenBalance.div(2); + uint256 otherHalf = contractTokenBalance.sub(half); + + // capture the contract's current ETH balance. + // this is so that we can capture exactly the amount of ETH that the + // swap creates, and not make the liquidity event include any ETH that + // has been manually sent to the contract + uint256 initialBalance = address(this).balance; + + // swap tokens for ETH + swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered + + // how much ETH did we just swap into? + uint256 newBalance = address(this).balance.sub(initialBalance); + + // add liquidity to uniswap + addLiquidity(otherHalf, newBalance); + + emit SwapAndLiquify(half, newBalance, otherHalf); + } + + function swapTokensForEth(uint256 tokenAmount) private { + // generate the uniswap pair path of token -> weth + address[] memory path = new address[](2); + path[0] = address(this); + path[1] = uniswapV2Router.WETH(); + + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // make the swap + uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( + tokenAmount, + 0, // accept any amount of ETH + path, + address(this), + block.timestamp + ); + } + + function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { + // approve token transfer to cover all possible scenarios + _approve(address(this), address(uniswapV2Router), tokenAmount); + + // add the liquidity + uniswapV2Router.addLiquidityETH{value: ethAmount}( + address(this), + tokenAmount, + 0, // slippage is unavoidable + 0, // slippage is unavoidable + dead, + block.timestamp + ); + } + + //this method is responsible for taking all fee, if takeFee is true + // SWC-135-Code With No Effects: L1103 - L1121 + function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { + if(!takeFee) + removeAllFee(); + + if (_isExcluded[sender] && !_isExcluded[recipient]) { + _transferFromExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && _isExcluded[recipient]) { + _transferToExcluded(sender, recipient, amount); + } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { + _transferStandard(sender, recipient, amount); + } else if (_isExcluded[sender] && _isExcluded[recipient]) { + _transferBothExcluded(sender, recipient, amount); + } else { + _transferStandard(sender, recipient, amount); + } + + if(!takeFee) + restoreAllFee(); + } + + function _transferStandard(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + +// SWC-135-Code With No Effects: L1134 - L1143 + function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + +// SWC-135-Code With No Effects: L1145 - L1153 + function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { + (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); + _tOwned[sender] = _tOwned[sender].sub(tAmount); + _rOwned[sender] = _rOwned[sender].sub(rAmount); + _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); + _takeLiquidity(tLiquidity); + _reflectFee(rFee, tFee); + emit Transfer(sender, recipient, tTransferAmount); + } + + function disableFees() public onlyOwner { + prevLiqFee = _liquidityFee; + prevTaxFee = _taxFee; + + _maxTxAmount = _tTotal; + _liquidityFee = 0; + _taxFee = 0; + swapAndLiquifyEnabled = false; + } + + function enableFees() public onlyOwner { + _maxTxAmount = _tTotal; + _liquidityFee = prevLiqFee; + _taxFee = prevTaxFee; + swapAndLiquifyEnabled = true; + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..b465fa35c3f --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = false; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..235ba754875 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/CSC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/CSC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..9c1ee767989 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/CSC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (true) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..0a6d0cfe492 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..867de6e7348 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + /* emit Transfer(sender, recipient, amount); */ + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..a5d7cdbaa3c --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..d67c1709e27 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..e921676a441 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..2428a2fea0c --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/MOI/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/MOI/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..9d49be9e5a3 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/MOI/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external onlyAdmin { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/MOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/MOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..1d33ecd79e0 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/MOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public onlyAdmin { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..a9c92da8f55 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,730 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..380093934e5 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,730 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..ca7fdc93576 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/SKI/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/SKI/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..4a985de873a --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/SKI/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(super.totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..af8a22da159 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/TOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/TOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..f122348d13c --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/TOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return tx.origin; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/UORD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/UORD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..99f73f7591e --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/UORD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || _initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..450bd884730 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/1/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool public _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..b676fc9d567 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a + b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a <= 0) { + return 0; + } + + uint256 c = a + b; + require(c + a <= b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b >= 0, errorMessage); + uint256 c = a + b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..4b052e37715 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes storage) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string storage name_, string storage symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string storage name_, string storage symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string storage) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string storage) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..bca6523f26c --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b > 0, errorMessage); */ + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b != 0, errorMessage); */ + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + /* require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); */ + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + /* require(sender != address(0), "ERC20: transfer from the zero address"); */ + /* require(recipient != address(0), "ERC20: transfer to the zero address"); */ + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + /* require(account != address(0), "ERC20: mint to the zero address"); */ + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + /* require(account != address(0), "ERC20: burn from the zero address"); */ + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..ab71b7bd95e --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) public pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) public pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) public pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() public view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() public initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..1107ed2ecc2 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 1, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 1; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[49] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 17; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(1), "ERC20: transfer from the zero address"); + require(recipient != address(1), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(1), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..2eb2dbc3a91 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,700 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..f678826c585 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + /* return 0; */ + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + /* return c; */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + /* return div(a, b, "SafeMath: division by zero"); */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + /* return c; */ + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + /* return mod(a, b, "SafeMath: modulo by zero"); */ + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + /* return a % b; */ + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + /* return cs == 0; */ + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..72fd8421548 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/10/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool public _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool public _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] public __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 public _totalSupply; + + string public _name; + string public _symbol; + uint8 public _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] public __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address internal admin; + address internal candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..635e8f3fb3a --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = false; + _initialized = false; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..2912230bdfe --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/CSC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/CSC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..1b8032073cd --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/CSC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (true) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (true) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..974bfa337a0 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..d2d9b912aa3 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + /* emit Transfer(sender, recipient, amount); */ + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + /* emit Transfer(address(0), account, amount); */ + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..2fcec384058 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..1ef7631e789 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..739fc843464 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..5f45706bd5a --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..3cd523dd922 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,721 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..3a50566455e --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,728 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + + + /** + * @dev See {IERC20-balanceOf}. + */ + + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..36bd2ae3511 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..83ce69a493a --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, ""); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/TOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/TOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..44ac7564c36 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/TOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return tx.origin; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(tx.origin == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/UORD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/UORD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..eb2c05d8e46 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/UORD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || _initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = _initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..68ec9c45f40 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/2/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool public _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool public _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..b4b7795964a --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = false; + _initialized = false; + } + + _; + + if (isTopLevelCall) { + _initializing = true; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..e9aa763c835 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/CSC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/CSC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..ba00921a6ce --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/CSC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (true) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (true) { + _initializing = true; + _initialized = true; + } + + _; + + if (true) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..9efb80bea0d --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..3e20d152f67 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + /* emit Transfer(sender, recipient, amount); */ + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + /* emit Transfer(address(0), account, amount); */ + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + /* emit Transfer(account, address(0), amount); */ + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..3f1477bef08 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..8804f3bc897 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..d17ce8ab15c --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..cb45e575e63 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..ab3375a94b0 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,719 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..a326fb7410f --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,725 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + + + /** + * @dev See {IERC20-balanceOf}. + */ + + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..d2b5dcfb624 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..5a53935d930 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, ""); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, ""); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/TOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/TOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..6b9274499e4 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/TOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return tx.origin; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(tx.origin == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((tx.origin == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..d346a10deb9 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/3/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool public _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool public _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] public __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..585bb56029f --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = false; + _initialized = false; + } + + _; + + if (isTopLevelCall) { + _initializing = true; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return false; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..61b37a90393 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a + b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..1ab03e46a26 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes storage) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..c4e460b3473 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + /* emit Transfer(sender, recipient, amount); */ + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + /* emit Transfer(address(0), account, amount); */ + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + /* emit Transfer(account, address(0), amount); */ + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); */ + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..e3f6cfcfa8d --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b > 0, errorMessage); */ + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..18d1e56122d --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) public pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..e22e1c2b79a --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 1, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..11451b856ec --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..db444f1a6ad --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,709 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..fdee63db427 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,723 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + + + /** + * @dev See {IERC20-balanceOf}. + */ + + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + + + /** + * @dev See {IERC20-allowance}. + */ + + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..bc1a335debf --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + /* return 0; */ + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..8db41631063 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, ""); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, ""); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..dc2a86cbff5 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/4/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool public _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool public _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] public __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 public _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..c46e6f92b0b --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = false; + _initialized = false; + } + + _; + + if (isTopLevelCall) { + _initializing = true; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return false; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return false; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..5381d2113ce --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a + b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a <= 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..d4ba61c33a3 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes storage) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string storage name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..aabdb530230 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + /* emit Transfer(sender, recipient, amount); */ + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + /* emit Transfer(address(0), account, amount); */ + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + /* emit Transfer(account, address(0), amount); */ + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); */ + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + /* emit AdminChanged(address(0), _admin); */ + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..bf376309c43 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b > 0, errorMessage); */ + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b != 0, errorMessage); */ + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..6645c1f36b6 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) public pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) public pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..5c27c97349e --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 1, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 1; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..b1a586bd2a4 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..34ba5f9f5d0 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,707 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..4c5dc5265a2 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,720 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + + + /** + * @dev See {IERC20-balanceOf}. + */ + + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + + + /** + * @dev See {IERC20-allowance}. + */ + + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..e77b5826a0e --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + /* return 0; */ + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + /* return c; */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..b8e8071cb0c --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, ""); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, ""); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..13222cd896e --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/5/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool public _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool public _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] public __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 public _totalSupply; + + string public _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..34301410872 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = false; + _initialized = false; + } + + _; + + if (isTopLevelCall) { + _initializing = true; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return false; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return false; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return false; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..72cacbcd0dc --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a + b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a <= 0) { + return 0; + } + + uint256 c = a + b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..80452b3c175 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes storage) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string storage name_, string storage symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..b9cdf691a45 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + /* emit Transfer(sender, recipient, amount); */ + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + /* emit Transfer(address(0), account, amount); */ + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + /* emit Transfer(account, address(0), amount); */ + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); */ + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + /* emit AdminChanged(address(0), _admin); */ + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + /* emit CandidateChanged(old, candidate); */ + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..c349238a4d2 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b > 0, errorMessage); */ + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b != 0, errorMessage); */ + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + /* require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); */ + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..5be9a2b909b --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) public pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) public pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..d1948d47e09 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 1, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 1; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[49] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..ea047c258ed --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..1f679c2642a --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,700 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..c2d7e47b521 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/ORFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,708 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + + + /** + * @dev See {IERC20-balanceOf}. + */ + + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + + + /** + * @dev See {IERC20-allowance}. + */ + + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..dd678c8f7dd --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + /* return 0; */ + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + /* return c; */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + /* return div(a, b, "SafeMath: division by zero"); */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..b85ed0e4614 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, ""); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, ""); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, ""); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..1ced0053335 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/6/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool public _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool public _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] public __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 public _totalSupply; + + string public _name; + string public _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..e32f0e525c9 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = false; + _initialized = false; + } + + _; + + if (isTopLevelCall) { + _initializing = true; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return false; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return false; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return false; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return false; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..fe6589bd6be --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a + b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a <= 0) { + return 0; + } + + uint256 c = a + b; + require(c + a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..c09f267771f --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes storage) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string storage name_, string storage symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string storage name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..e86e17b0865 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/EED/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + /* emit Transfer(sender, recipient, amount); */ + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + /* emit Transfer(address(0), account, amount); */ + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + /* emit Transfer(account, address(0), amount); */ + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); */ + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + /* emit AdminChanged(address(0), _admin); */ + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + /* emit CandidateChanged(old, candidate); */ + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + /* emit AdminChanged(old, admin); */ + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..1fb9eacef63 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b > 0, errorMessage); */ + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b != 0, errorMessage); */ + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + /* require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); */ + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + /* require(sender != address(0), "ERC20: transfer from the zero address"); */ + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..de609952fc6 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) public pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) public pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) public pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..1fbcc6a363f --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 1, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 1; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[49] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 17; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..edabd09c6db --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..a2373ca950b --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,700 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..598d70cf006 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + /* return 0; */ + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + /* return c; */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + /* return div(a, b, "SafeMath: division by zero"); */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + /* return c; */ + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..b5f8f328bb3 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, ""); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, ""); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, ""); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, ""); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..29bd62bdb06 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/7/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool public _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool public _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] public __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 public _totalSupply; + + string public _name; + string public _symbol; + uint8 public _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..de7030d2f74 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/BLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = false; + _initialized = false; + } + + _; + + if (isTopLevelCall) { + _initializing = true; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return false; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return false; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return false; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return false; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return false; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..5cf1994620e --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a + b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a <= 0) { + return 0; + } + + uint256 c = a + b; + require(c + a <= b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..bc451f7bade --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes storage) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string storage name_, string storage symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string storage name_, string storage symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..c8cbcd05b87 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b > 0, errorMessage); */ + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b != 0, errorMessage); */ + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + /* require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); */ + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + /* require(sender != address(0), "ERC20: transfer from the zero address"); */ + /* require(recipient != address(0), "ERC20: transfer to the zero address"); */ + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..38f55e397cc --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) public pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) public pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) public pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..74df28bc28a --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 1, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 1; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[49] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 17; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(1), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..eb3dbac27c3 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..50621be6b6d --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,700 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..90a73227bae --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + /* return 0; */ + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + /* return c; */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + /* return div(a, b, "SafeMath: division by zero"); */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + /* return c; */ + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + /* return mod(a, b, "SafeMath: modulo by zero"); */ + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..3eb15199ab2 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, ""); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, ""); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, ""); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, ""); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..951a8747deb --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/8/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool public _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool public _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] public __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 public _totalSupply; + + string public _name; + string public _symbol; + uint8 public _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] public __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..599c2a63370 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/BOR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a - b; + require(c > a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b < a, errorMessage); + uint256 c = a + b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a <= 0) { + return 0; + } + + uint256 c = a + b; + require(c + a <= b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b >= 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..35eb55f87f2 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/DLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string storage errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes storage) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string storage name_, string storage symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string storage name_, string storage symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string storage) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..b4c0a8d145c --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/EHC/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + /* require(c >= a, "SafeMath: addition overflow"); */ + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b <= a, errorMessage); */ + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + /* require(c / a == b, "SafeMath: multiplication overflow"); */ + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b > 0, errorMessage); */ + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + /* require(b != 0, errorMessage); */ + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + /* require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); */ + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + /* require(sender != address(0), "ERC20: transfer from the zero address"); */ + /* require(recipient != address(0), "ERC20: transfer to the zero address"); */ + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + /* require(account != address(0), "ERC20: mint to the zero address"); */ + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..0fb645ce6c6 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/FVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) public pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) public pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) public pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) public pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) public pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() public view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..daa89c71617 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/ILR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 1) { + return 1; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 1, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 1, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 1; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[49] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 17; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(1), "ERC20: transfer from the zero address"); + require(recipient != address(1), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..7e5b825edc7 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/MOD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..4902b485d47 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/OLFD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,700 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..f3102710fda --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/RSD/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + /* return c; */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + /* return sub(a, b, "SafeMath: subtraction overflow"); */ + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + /* return c; */ + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + /* return 0; */ + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + /* return c; */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + /* return div(a, b, "SafeMath: division by zero"); */ + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + /* return c; */ + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + /* return mod(a, b, "SafeMath: modulo by zero"); */ + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + /* return a % b; */ + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..34399674709 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/SLR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, ""); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, ""); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, ""); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, ""); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, ""); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("", ""); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..c0d9bb3d149 --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/9/VVR/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool public _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool public _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] public __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 public _totalSupply; + + string public _name; + string public _symbol; + uint8 public _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] public __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address internal admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/original/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/original/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol new file mode 100644 index 00000000000..45b00bd279a --- /dev/null +++ b/contracts/mutants/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3/original/BSCSCAN-2ae9952c1038dA3DafebA026B96053F24CBc03b3.sol @@ -0,0 +1,732 @@ +/** + *Submitted for verification at BscScan.com on 2021-01-15 +*/ + +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.0 <0.8.0; + +/** + * @dev Wrappers over Solidity's arithmetic operations with added overflow + * checks. + * + * Arithmetic operations in Solidity wrap on overflow. This can easily result + * in bugs, because programmers usually assume that an overflow raises an + * error, which is the standard behavior in high level programming languages. + * `SafeMath` restores this intuition by reverting the transaction when an + * operation overflows. + * + * Using this library instead of the unchecked operations eliminates an entire + * class of bugs, so it's recommended to use it always. + */ +library SafeMathUpgradeable { + /** + * @dev Returns the addition of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `+` operator. + * + * Requirements: + * + * - Addition cannot overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "SafeMath: addition overflow"); + + return c; + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + return sub(a, b, "SafeMath: subtraction overflow"); + } + + /** + * @dev Returns the subtraction of two unsigned integers, reverting with custom message on + * overflow (when the result is negative). + * + * Counterpart to Solidity's `-` operator. + * + * Requirements: + * + * - Subtraction cannot overflow. + */ + function sub( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b <= a, errorMessage); + uint256 c = a - b; + + return c; + } + + /** + * @dev Returns the multiplication of two unsigned integers, reverting on + * overflow. + * + * Counterpart to Solidity's `*` operator. + * + * Requirements: + * + * - Multiplication cannot overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b, "SafeMath: multiplication overflow"); + + return c; + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return div(a, b, "SafeMath: division by zero"); + } + + /** + * @dev Returns the integer division of two unsigned integers. Reverts with custom message on + * division by zero. The result is rounded towards zero. + * + * Counterpart to Solidity's `/` operator. Note: this function uses a + * `revert` opcode (which leaves remaining gas untouched) while Solidity + * uses an invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function div( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b > 0, errorMessage); + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + return mod(a, b, "SafeMath: modulo by zero"); + } + + /** + * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), + * Reverts with custom message when dividing by zero. + * + * Counterpart to Solidity's `%` operator. This function uses a `revert` + * opcode (which leaves remaining gas untouched) while Solidity uses an + * invalid opcode to revert (consuming all remaining gas). + * + * Requirements: + * + * - The divisor cannot be zero. + */ + function mod( + uint256 a, + uint256 b, + string memory errorMessage + ) internal pure returns (uint256) { + require(b != 0, errorMessage); + return a % b; + } +} + +/** + * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed + * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an + * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer + * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. + * + * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as + * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. + * + * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure + * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. + */ +abstract contract Initializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); + + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + + _; + + if (isTopLevelCall) { + _initializing = false; + } + } + + /// @dev Returns true if and only if the function is running in the constructor + function _isConstructor() private view returns (bool) { + // extcodesize checks the size of the code stored in an address, and + // address returns the current address. Since the code is still not + // deployed when running a constructor, any checks on its code size will + // yield zero, making it an effective way to detect if a contract is + // under construction or not. + address self = address(this); + uint256 cs; + // solhint-disable-next-line no-inline-assembly + assembly { + cs := extcodesize(self) + } + return cs == 0; + } +} + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with GSN meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract ContextUpgradeable is Initializable { + function __Context_init() internal initializer { + __Context_init_unchained(); + } + + function __Context_init_unchained() internal initializer {} + + function _msgSender() internal view virtual returns (address payable) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes memory) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } + + uint256[50] private __gap; +} + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20Upgradeable { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable { + using SafeMathUpgradeable for uint256; + + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}, initializes {decimals} with + * a default value of 18. + * + * To select a different value for {decimals}, use {_setupDecimals}. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + function __ERC20_init(string memory name_, string memory symbol_) internal initializer { + __Context_init_unchained(); + __ERC20_init_unchained(name_, symbol_); + } + + function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer { + _name = name_; + _symbol = symbol_; + _decimals = 18; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is + * called. + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + // SWC-105-Unprotected Ether Withdrawal: L454- L457 + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + _approve( + sender, + _msgSender(), + _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") + ); + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + _approve( + _msgSender(), + spender, + _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") + ); + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); + _balances[recipient] = _balances[recipient].add(amount); + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply = _totalSupply.add(amount); + _balances[account] = _balances[account].add(amount); + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); + _totalSupply = _totalSupply.sub(amount); + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) internal virtual { + 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); + } + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual {} + + uint256[44] private __gap; +} + +/** + * @title LnAdminUpgradeable + * + * @dev This is an upgradeable version of `LnAdmin` by replacing the constructor with + * an initializer and reserving storage slots. + */ +contract LnAdminUpgradeable is Initializable { + event CandidateChanged(address oldCandidate, address newCandidate); + event AdminChanged(address oldAdmin, address newAdmin); + + address public admin; + address public candidate; + + function __LnAdminUpgradeable_init(address _admin) public initializer { + require(_admin != address(0), "LnAdminUpgradeable: zero address"); + admin = _admin; + emit AdminChanged(address(0), _admin); + } + + function setCandidate(address _candidate) external onlyAdmin { + address old = candidate; + candidate = _candidate; + emit CandidateChanged(old, candidate); + } + + function becomeAdmin() external { + require(msg.sender == candidate, "LnAdminUpgradeable: only candidate can become admin"); + address old = admin; + admin = candidate; + emit AdminChanged(old, admin); + } + + modifier onlyAdmin { + require((msg.sender == admin), "LnAdminUpgradeable: only the contract admin can perform this action"); + _; + } + + // Reserved storage space to allow for layout changes in the future. + uint256[48] private __gap; +} + +contract LinearFinance is ERC20Upgradeable, LnAdminUpgradeable { + using SafeMathUpgradeable for uint256; + + uint256 public constant MAX_SUPPLY = 10000000000e18; + + function __LinearFinance_init(address _admin) public initializer { + __ERC20_init("Linear Token", "LINA"); + __LnAdminUpgradeable_init(_admin); + } + + function mint(address account, uint256 amount) external onlyAdmin { + require(totalSupply().add(amount) <= MAX_SUPPLY, "LinearFinance: max supply exceeded"); + _mint(account, amount); + } + + function burn(address account, uint amount) external onlyAdmin { + _burn(account, amount); + } +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/1/BOR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/1/BOR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..033baa038e9 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/1/BOR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x - 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/1/CCD/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/1/CCD/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..5502be9a75f --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/1/CCD/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/1/DLR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/1/DLR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..ae3cf835c1a --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/1/DLR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string storage) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/1/FVR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/1/FVR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..d03cdaaf910 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/1/FVR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() public pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/1/ILR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/1/ILR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..4bbb5ac0bd5 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/1/ILR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(8); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/1/OLFD/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/1/OLFD/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..132e6957ee8 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/1/OLFD/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/1/RSD/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/1/RSD/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..0ecfb0d2bcb --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/1/RSD/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + /* return uint8(9); */ + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/1/SLR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/1/SLR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..15f8ae664c4 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/1/SLR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return ""; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/1/VVR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/1/VVR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..0deda87d7c2 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/1/VVR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 internal constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/2/BOR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/2/BOR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..7cb58d2f2f4 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/2/BOR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x - 1) + 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/2/DLR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/2/DLR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..20de453e463 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/2/DLR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string storage) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string storage) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/2/FVR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/2/FVR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..33bd28bf8dc --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/2/FVR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() public pure returns (uint8) { + return uint8(9); + } + + function name() public pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/2/ILR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/2/ILR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..f1f5ad72cc8 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/2/ILR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(8); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 0) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/2/OLFD/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/2/OLFD/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..b0606cfab60 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/2/OLFD/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + + + + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/2/RSD/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/2/RSD/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..c61fc0d6ebd --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/2/RSD/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + /* return uint8(9); */ + } + + function name() external pure returns (string memory) { + /* return "BT In The Citadel"; */ + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/2/SLR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/2/SLR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..664d35dc499 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/2/SLR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return ""; + } + + function symbol() external pure returns (string memory) { + return ""; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/2/VVR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/2/VVR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..5d3bcc499c9 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/2/VVR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 internal constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards internal constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/3/BOR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/3/BOR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..2f5dfce3e7a --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/3/BOR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x - 1) + 2; + y = x; + while (z <= y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/3/FVR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/3/FVR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..99532a2e03e --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/3/FVR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() public pure returns (uint8) { + return uint8(9); + } + + function name() public pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() public pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/3/ILR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/3/ILR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..979eb63f0e3 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/3/ILR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(8); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 0) / 1; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/3/OLFD/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/3/OLFD/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..7f0ad0b35d2 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/3/OLFD/BT-ETHTheCitadel.sol @@ -0,0 +1,77 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + + + + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/3/RSD/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/3/RSD/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..6558fc8bb06 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/3/RSD/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + /* return uint8(9); */ + } + + function name() external pure returns (string memory) { + /* return "BT In The Citadel"; */ + } + + function symbol() external pure returns (string memory) { + /* return "BT C"; */ + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/4/BOR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/4/BOR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..f10b515f9b8 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/4/BOR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x - 1) + 2; + y = x; + while (z <= y) { + y = z; + z = (x + z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/4/FVR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/4/FVR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..b2bb75566f7 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/4/FVR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() public pure returns (uint8) { + return uint8(9); + } + + function name() public pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() public pure returns (string memory) { + return "BT C"; + } + + function totalSupply() public view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/4/ILR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/4/ILR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..3d35cf5acef --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/4/ILR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(8); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 0) / 1; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 1; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/4/OLFD/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/4/OLFD/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..91461cf3b64 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/4/OLFD/BT-ETHTheCitadel.sol @@ -0,0 +1,75 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + + + + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/4/RSD/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/4/RSD/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..d523474c0cc --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/4/RSD/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + /* return uint8(9); */ + } + + function name() external pure returns (string memory) { + /* return "BT In The Citadel"; */ + } + + function symbol() external pure returns (string memory) { + /* return "BT C"; */ + } + + function totalSupply() external view returns (uint256) { + /* return sqrt(votes.totalSupply()); */ + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/5/BOR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/5/BOR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..b957d503505 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/5/BOR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x - 1) + 2; + y = x; + while (z <= y) { + y = z; + z = (x + z - z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/5/FVR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/5/FVR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..593c0630668 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/5/FVR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() public pure returns (uint8) { + return uint8(9); + } + + function name() public pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() public pure returns (string memory) { + return "BT C"; + } + + function totalSupply() public view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) public view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/5/OLFD/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/5/OLFD/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..574761ac96b --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/5/OLFD/BT-ETHTheCitadel.sol @@ -0,0 +1,72 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + + + + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + + + + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/5/RSD/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/5/RSD/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..5d8bf5cf40f --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/5/RSD/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + /* return uint8(9); */ + } + + function name() external pure returns (string memory) { + /* return "BT In The Citadel"; */ + } + + function symbol() external pure returns (string memory) { + /* return "BT C"; */ + } + + function totalSupply() external view returns (uint256) { + /* return sqrt(votes.totalSupply()); */ + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + /* return sqrt(_votes); */ + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/6/BOR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/6/BOR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..ac043f8a4c5 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/6/BOR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x - 1) + 2; + y = x; + while (z <= y) { + y = z; + z = (x + z - z) + 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/6/FVR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/6/FVR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..577d8a6b146 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/6/FVR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() public pure returns (uint8) { + return uint8(9); + } + + function name() public pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() public pure returns (string memory) { + return "BT C"; + } + + function totalSupply() public view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) public view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) external pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/7/FVR/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/7/FVR/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..827b0a3f491 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/7/FVR/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() public pure returns (uint8) { + return uint8(9); + } + + function name() public pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() public pure returns (string memory) { + return "BT C"; + } + + function totalSupply() public view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) public view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) external pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() internal {} +} \ No newline at end of file diff --git a/contracts/mutants/BT-ETHTheCitadel/original/BT-ETHTheCitadel.sol b/contracts/mutants/BT-ETHTheCitadel/original/BT-ETHTheCitadel.sol new file mode 100644 index 00000000000..811d76d4081 --- /dev/null +++ b/contracts/mutants/BT-ETHTheCitadel/original/BT-ETHTheCitadel.sol @@ -0,0 +1,80 @@ +pragma solidity ^0.6.7; + +interface IERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +interface StakingRewards { + function balanceOf(address) + external + view + returns (uint256); +} + +contract BT_ETHVoteProxy { + IERC20 public constant votes = IERC20( + 0x1aDAC7dE5C5d9894a4F6A80868AdE96F8a2ed0eb + ); + + StakingRewards public constant stakingRewards = StakingRewards( + 0xC74d15D2e61414C0975B9DC31fA8921c9909D08D + ); + + function decimals() external pure returns (uint8) { + return uint8(9); + } + + function name() external pure returns (string memory) { + return "BT In The Citadel"; + } + + function symbol() external pure returns (string memory) { + return "BT C"; + } + + function totalSupply() external view returns (uint256) { + return sqrt(votes.totalSupply()); + } + + function balanceOf(address _voter) external view returns (uint256) { + uint256 _votes = stakingRewards.balanceOf(_voter); + return sqrt(_votes); + } + + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + } + + constructor() public {} +} \ No newline at end of file diff --git a/contracts/mutants/BTCB/1/FVR/BTCB.sol b/contracts/mutants/BTCB/1/FVR/BTCB.sol new file mode 100644 index 00000000000..67ac95f6868 --- /dev/null +++ b/contracts/mutants/BTCB/1/FVR/BTCB.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; + +import "./ERC20.sol"; +import "../utils/Ownable.sol"; + +contract BTCB is ERC20("BTCB (test)", "BTCB"), Ownable { + function mint(address _to, uint256 _amount) external onlyOwner { + _mint(_to, _amount); + } +} diff --git a/contracts/mutants/BTCB/1/SLR/BTCB.sol b/contracts/mutants/BTCB/1/SLR/BTCB.sol new file mode 100644 index 00000000000..bb867be8a39 --- /dev/null +++ b/contracts/mutants/BTCB/1/SLR/BTCB.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; + +import "./ERC20.sol"; +import "../utils/Ownable.sol"; + +contract BTCB is ERC20("", "BTCB"), Ownable { + function mint(address _to, uint256 _amount) public onlyOwner { + _mint(_to, _amount); + } +} diff --git a/contracts/mutants/BTCB/2/SLR/BTCB.sol b/contracts/mutants/BTCB/2/SLR/BTCB.sol new file mode 100644 index 00000000000..9b60249f855 --- /dev/null +++ b/contracts/mutants/BTCB/2/SLR/BTCB.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; + +import "./ERC20.sol"; +import "../utils/Ownable.sol"; + +contract BTCB is ERC20("", ""), Ownable { + function mint(address _to, uint256 _amount) public onlyOwner { + _mint(_to, _amount); + } +} diff --git a/contracts/mutants/BTCB/original/BTCB.sol b/contracts/mutants/BTCB/original/BTCB.sol new file mode 100644 index 00000000000..f22d88d803b --- /dev/null +++ b/contracts/mutants/BTCB/original/BTCB.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.6.12; + +import "./ERC20.sol"; +import "../utils/Ownable.sol"; + +contract BTCB is ERC20("BTCB (test)", "BTCB"), Ownable { + function mint(address _to, uint256 _amount) public onlyOwner { + _mint(_to, _amount); + } +} diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/BOR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/BOR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..23a5cf4db4f --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/BOR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 + 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/CCD/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/CCD/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..51ca21b066c --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/CCD/BTCDaiRebalancingManager.sol @@ -0,0 +1,310 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/CSC/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/CSC/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..c485703fcd4 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/CSC/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (true) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/DLR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/DLR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..c6694bdd6ef --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/DLR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/ECS/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/ECS/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..628de6a2f58 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/ECS/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes1("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/EED/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/EED/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..20a2341b17f --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/EED/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + /* emit LogManagerProposal( + btcPrice + ); */ + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/EHC/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/EHC/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..7211a7f8191 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/EHC/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + /* require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); */ + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/FVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/FVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..fdefda66168 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/FVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + internal + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/ILR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/ILR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..47b2a2dff22 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/ILR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 0; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/RSD/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/RSD/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..d465a4c6888 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/RSD/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + /* return currentSetDollarAmount; */ + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/RVS/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/RVS/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..b85b4e9b50e --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/RVS/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetDollarAmount, nextSetNaturalUnit, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/SCEC/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/SCEC/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..b85b4e9b50e --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/SCEC/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetDollarAmount, nextSetNaturalUnit, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/SFR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/SFR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..5c90bc56205 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/SFR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/SLR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/SLR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..f343eb1e16c --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/SLR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32(""), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/1/VVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/1/VVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..64c6332aa4b --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/1/VVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/10/DLR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/10/DLR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..070cdb6a8fd --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/10/DLR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] storage assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] storage nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] storage nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] storage) + { + // Initialize set token parameters + uint256[] storage nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/10/ILR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/10/ILR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..60ef8efb034 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/10/ILR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 0; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + + // Equal to $1 + uint256 constant DAI_PRICE = 9 ** 17; + uint256 constant DAI_DECIMALS = 17; + uint256 constant BTC_DECIMALS = 7; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 9 ** 9; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[1] memory _multipliers, + uint256[1] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/10/VVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/10/VVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..f4d3235b3ca --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/10/VVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 1; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant public constant DAI_PRICE = 10 ** 18; + uint256 constant public constant DAI_DECIMALS = 18; + uint256 constant public constant BTC_DECIMALS = 8; + uint256 constant public constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address internal daiAddress; + address internal btcAddress; + address internal setTokenFactory; + + address internal btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/2/BOR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/2/BOR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..9e87ed500e3 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/2/BOR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 + 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 + 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/2/CSC/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/2/CSC/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..ef4dfd1ba45 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/2/CSC/BTCDaiRebalancingManager.sol @@ -0,0 +1,335 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (true) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/2/DLR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/2/DLR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..f25d28c893b --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/2/DLR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/2/ECS/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/2/ECS/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..a099fc2c2b5 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/2/ECS/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes1("DAIBTC"), + bytes1("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/2/EHC/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/2/EHC/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..57892d08b4a --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/2/EHC/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + /* require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); */ + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + /* require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); */ + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/2/FVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/2/FVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..d02621d1617 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/2/FVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + internal + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + public + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/2/ILR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/2/ILR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..049248a21df --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/2/ILR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 0; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/2/RSD/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/2/RSD/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..1ee1df43286 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/2/RSD/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + /* return currentSetDollarAmount; */ + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + /* return (nextSetAddress, nextSetDollarAmount); */ + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/2/SFR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/2/SFR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..af216087e48 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/2/SFR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).mul(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/2/SLR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/2/SLR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..687bca82994 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/2/SLR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32(""), + bytes32(""), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/2/VVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/2/VVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..bd731ba9bb4 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/2/VVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 1; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/3/BOR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/3/BOR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..e6a1b917cbc --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/3/BOR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 + 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 + 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] > _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/3/DLR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/3/DLR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..9bc4b279f76 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/3/DLR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/3/FVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/3/FVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..434d40325f5 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/3/FVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + internal + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + public + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + public + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/3/ILR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/3/ILR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..7b0837cb599 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/3/ILR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 0; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + + // Equal to $1 + uint256 constant DAI_PRICE = 9 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/3/RSD/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/3/RSD/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..6dbf65c3092 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/3/RSD/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + /* return currentSetDollarAmount; */ + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + /* return (nextSetAddress, nextSetDollarAmount); */ + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + /* return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); */ + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/3/SFR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/3/SFR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..499ac309f2d --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/3/SFR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).mul(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.add(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/3/VVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/3/VVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..a56ad31a0f0 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/3/VVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 1; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant public constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/4/BOR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/4/BOR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..e8fe26e3d1a --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/4/BOR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 + 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 + 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] > _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) > minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/4/DLR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/4/DLR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..762a179b1d0 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/4/DLR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/4/FVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/4/FVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..37930830418 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/4/FVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + internal + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + public + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + public + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + public + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/4/ILR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/4/ILR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..f6f2a210060 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/4/ILR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 0; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + + // Equal to $1 + uint256 constant DAI_PRICE = 9 ** 17; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/4/SFR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/4/SFR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..283f16a8412 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/4/SFR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).mul(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.add(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).mul(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/4/VVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/4/VVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..c0160182835 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/4/VVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 1; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant public constant DAI_PRICE = 10 ** 18; + uint256 constant public constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/5/BOR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/5/BOR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..4f24ac97670 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/5/BOR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 + 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 + 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] > _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) > minimumUpperThreshold && + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/5/DLR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/5/DLR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..532ea1d83ec --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/5/DLR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] storage assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/5/FVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/5/FVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..785cb6b4bf5 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/5/FVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + internal + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + public + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + public + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + public + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + public + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/5/ILR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/5/ILR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..54326151f3f --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/5/ILR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 0; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + + // Equal to $1 + uint256 constant DAI_PRICE = 9 ** 17; + uint256 constant DAI_DECIMALS = 17; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/5/SFR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/5/SFR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..196d00da9d7 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/5/SFR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).mul(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.add(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).mul(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.add(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/5/VVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/5/VVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..c87c24bb352 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/5/VVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 1; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant public constant DAI_PRICE = 10 ** 18; + uint256 constant public constant DAI_DECIMALS = 18; + uint256 constant public constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/6/BOR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/6/BOR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..b3225cf06fe --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/6/BOR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 + 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 + 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] > _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) > minimumUpperThreshold && + daiDollarAmount.mul(100).div(currentSetDollarAmount) <= maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/6/DLR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/6/DLR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..80583fa8842 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/6/DLR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] storage assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] storage nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/6/ILR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/6/ILR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..d1791d71a38 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/6/ILR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 0; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + + // Equal to $1 + uint256 constant DAI_PRICE = 9 ** 17; + uint256 constant DAI_DECIMALS = 17; + uint256 constant BTC_DECIMALS = 7; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/6/SFR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/6/SFR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..2db98469adb --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/6/SFR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).mul(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.add(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).mul(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.add(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.add(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/6/VVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/6/VVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..3bf03c37291 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/6/VVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 1; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant public constant DAI_PRICE = 10 ** 18; + uint256 constant public constant DAI_DECIMALS = 18; + uint256 constant public constant BTC_DECIMALS = 8; + uint256 constant public constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/7/BOR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/7/BOR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..f6bf9caebb3 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/7/BOR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 + 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 + 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] > _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) > minimumUpperThreshold && + daiDollarAmount.mul(100).div(currentSetDollarAmount) <= maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice > DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/7/DLR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/7/DLR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..b3861d4a920 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/7/DLR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] storage assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] storage nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] storage nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/7/ILR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/7/ILR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..5eab21d3cb9 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/7/ILR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 0; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + + // Equal to $1 + uint256 constant DAI_PRICE = 9 ** 17; + uint256 constant DAI_DECIMALS = 17; + uint256 constant BTC_DECIMALS = 7; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 9 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/7/SFR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/7/SFR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..ea19c0444db --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/7/SFR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).mul(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.add(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).mul(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.add(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.add(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).mul(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/7/VVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/7/VVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..3f1e4883a15 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/7/VVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 1; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant public constant DAI_PRICE = 10 ** 18; + uint256 constant public constant DAI_DECIMALS = 18; + uint256 constant public constant BTC_DECIMALS = 8; + uint256 constant public constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address internal daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/8/DLR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/8/DLR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..49e0d30b7b6 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/8/DLR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] storage assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] storage nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] storage nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] storage) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/8/ILR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/8/ILR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..85a2399a273 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/8/ILR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 0; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + + // Equal to $1 + uint256 constant DAI_PRICE = 9 ** 17; + uint256 constant DAI_DECIMALS = 17; + uint256 constant BTC_DECIMALS = 7; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 9 ** 9; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/8/SFR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/8/SFR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..5796315e2f1 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/8/SFR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).mul(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.add(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).mul(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.add(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.add(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).mul(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.add(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/8/VVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/8/VVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..f15c6f902a4 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/8/VVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 1; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant public constant DAI_PRICE = 10 ** 18; + uint256 constant public constant DAI_DECIMALS = 18; + uint256 constant public constant BTC_DECIMALS = 8; + uint256 constant public constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address internal daiAddress; + address internal btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/9/DLR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/9/DLR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..140f477a822 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/9/DLR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] storage assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] storage nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] storage nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] storage) + { + // Initialize set token parameters + uint256[] storage nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/9/ILR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/9/ILR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..1244f8015a6 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/9/ILR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 0; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + + // Equal to $1 + uint256 constant DAI_PRICE = 9 ** 17; + uint256 constant DAI_DECIMALS = 17; + uint256 constant BTC_DECIMALS = 7; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 9 ** 9; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[1] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/9/SFR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/9/SFR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..bc55481e2d5 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/9/SFR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).mul(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.add(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).mul(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.add(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.add(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).mul(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.add(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.add(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/9/VVR/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/9/VVR/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..fa273f3872a --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/9/VVR/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 1; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant public constant DAI_PRICE = 10 ** 18; + uint256 constant public constant DAI_DECIMALS = 18; + uint256 constant public constant BTC_DECIMALS = 8; + uint256 constant public constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address internal daiAddress; + address internal btcAddress; + address internal setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCDaiRebalancingManager/original/BTCDaiRebalancingManager.sol b/contracts/mutants/BTCDaiRebalancingManager/original/BTCDaiRebalancingManager.sol new file mode 100644 index 00000000000..d8d8c7ffcf2 --- /dev/null +++ b/contracts/mutants/BTCDaiRebalancingManager/original/BTCDaiRebalancingManager.sol @@ -0,0 +1,343 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCDaiRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCDai Rebalancing Set Token + */ +contract BTCDaiRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 1; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + + // Equal to $1 + uint256 constant DAI_PRICE = 10 ** 18; + uint256 constant DAI_DECIMALS = 18; + uint256 constant BTC_DECIMALS = 8; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public daiAddress; + address public btcAddress; + address public setTokenFactory; + + address public btcPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public daiMultiplier; + uint256 public btcMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * daiAllocation = daiMultiplier/(daiMultiplier + btcMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (daiMultiplier + btcMultiplier)*max(btcPrice, daiPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of btc medianizer + * @param _daiAddress The address of the Dai contract + * @param _btcAddress The address of the wrapped btc contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _multipliers Token multipliers used to determine allocation + * @param _allocationBounds Bounds to stop proposal if not enough deviation from expected allocation + * set to be [lowerBound, upperBound] + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _daiAddress, + address _btcAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + + daiAddress = _daiAddress; + btcAddress = _btcAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + daiMultiplier = _multipliers[0]; + btcMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken(btcPrice); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + ( + uint256 auctionStartPrice, + uint256 auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation as defined by maximumUpperThreshold + * and minimumLowerThreshold and return USD value of currentSet. + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // // Calculate dai dollar value in currentSet (in cents) + uint256 daiDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + DAI_PRICE, + currentSetNaturalUnit, + currentSetUnits[0], + DAI_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed enough to trigger buy or sell + require( + daiDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + daiDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal dollar value of one full BTC + * @return address The address of nextSet + * @return uint256 The dollar value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + ( + uint256 nextSetNaturalUnit, + uint256 nextSetDollarAmount, + uint256[] memory nextSetUnits + ) = calculateNextSetUnits( + _btcPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = daiAddress; + nextSetComponents[1] = btcAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("DAIBTC"), + bytes32("DAIBTC"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice + ) + private + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256[] memory nextSetUnits = new uint256[](2); + uint256 nextSetNaturalUnit = DECIMAL_DIFF_MULTIPLIER.mul(PRICE_PRECISION); + + if (_btcPrice >= DAI_PRICE) { + // Dai nextSetUnits is equal the USD Bitcoin price + uint256 daiUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(DAI_PRICE); + + // Create unit array and define natural unit + nextSetUnits[0] = daiUnits.mul(daiMultiplier).mul(PRICE_PRECISION); + nextSetUnits[1] = btcMultiplier.mul(PRICE_PRECISION); + } else { + // Calculate btc nextSetUnits as (daiPrice/btcPrice)*100. 100 is used to add + // precision. + uint256 btcDaiPrice = DAI_PRICE.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = daiMultiplier.mul(DECIMAL_DIFF_MULTIPLIER).mul(PRICE_PRECISION); + nextSetUnits[1] = btcDaiPrice.mul(btcMultiplier); + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = DAI_PRICE; + assetPrices[1] = _btcPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = DAI_DECIMALS; + assetDecimals[1] = BTC_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} \ No newline at end of file diff --git a/contracts/mutants/BTCETHRebalancingManager/1/BOR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/BOR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..d041de94db5 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/BOR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 + 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/1/CCD/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/CCD/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..2b1410b2a80 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/CCD/BTCETHRebalancingManager.sol @@ -0,0 +1,336 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/1/CSC/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/CSC/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..f3bb0dd79a7 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/CSC/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (true) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/1/DLR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/DLR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..a86f5f5ca87 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/DLR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/1/ECS/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/ECS/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..aba2037d51f --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/ECS/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes1("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/1/EED/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/EED/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..fb0a03e528a --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/EED/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + /* emit LogManagerProposal( + btcPrice, + ethPrice + ); */ + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/1/EHC/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/EHC/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..d89f1289881 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/EHC/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + /* require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); */ + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/1/FVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/FVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..29011caec3a --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/FVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + internal + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/1/ILR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/ILR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..b6874100ac8 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/ILR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 99; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/1/RSD/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/RSD/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..ac55c811d7c --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/RSD/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + /* return currentSetDollarAmount; */ + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/1/RVS/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/RVS/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..9a9489e32a7 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/RVS/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetDollarAmount, nextSetNaturalUnit, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/1/SCEC/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/SCEC/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..9a9489e32a7 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/SCEC/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetDollarAmount, nextSetNaturalUnit, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/1/SFR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/SFR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..cf1d2580540 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/SFR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/1/SLR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/SLR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..9b517d1d755 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/SLR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32(""), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/1/VVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/1/VVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..1cc8f3dee14 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/1/VVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/10/DLR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/10/DLR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..dc118aae82d --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/10/DLR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] storage assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] storage nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] storage nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] storage) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] storage nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/10/ILR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/10/ILR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..2102d453872 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/10/ILR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 99; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + uint256 constant BTC_DECIMALS = 7; + uint256 constant ETH_DECIMALS = 17; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 9 ** 9; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[1] memory _multipliers, + uint256[1] memory _allocationBounds + ) + public + { + require( + _allocationBounds[0] >= _allocationBounds[1], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/10/VVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/10/VVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..30e212a25cb --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/10/VVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 100; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant public constant BTC_DECIMALS = 8; + uint256 constant public constant ETH_DECIMALS = 18; + uint256 constant public constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address internal btcAddress; + address internal ethAddress; + address internal setTokenFactory; + + address internal btcPriceFeed; + address internal ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/2/BOR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/2/BOR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..bf38aae7b22 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/2/BOR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 + 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] > _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/2/CSC/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/2/CSC/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..fe607652499 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/2/CSC/BTCETHRebalancingManager.sol @@ -0,0 +1,360 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (true) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/2/DLR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/2/DLR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..58daa9e2c67 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/2/DLR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/2/ECS/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/2/ECS/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..d824cd94cca --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/2/ECS/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes1("BTCETH"), + bytes1("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/2/EHC/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/2/EHC/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..b9cdfbdcbde --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/2/EHC/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + /* require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); */ + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + /* require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); */ + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/2/FVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/2/FVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..0f624cb307b --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/2/FVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + internal + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + public + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/2/ILR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/2/ILR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..15f6791ebd6 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/2/ILR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 99; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/2/RSD/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/2/RSD/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..8d7d565829d --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/2/RSD/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + /* return currentSetDollarAmount; */ + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + /* return (nextSetAddress, nextSetDollarAmount); */ + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/2/SFR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/2/SFR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..b2ef16d9e10 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/2/SFR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).mul(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/2/SLR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/2/SLR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..b1fdcf33fbf --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/2/SLR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32(""), + bytes32(""), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/2/VVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/2/VVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..34c8bdf3974 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/2/VVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 100; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/3/BOR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/3/BOR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..fda626545d6 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/3/BOR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 + 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] > _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) > minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/3/DLR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/3/DLR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..51be0b0b8ae --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/3/DLR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/3/FVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/3/FVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..ea6ab545072 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/3/FVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + internal + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + public + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + public + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/3/ILR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/3/ILR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..d4b9a4699d1 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/3/ILR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 99; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + uint256 constant BTC_DECIMALS = 7; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/3/RSD/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/3/RSD/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..4b344b0d18b --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/3/RSD/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + /* return currentSetDollarAmount; */ + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + /* return (nextSetAddress, nextSetDollarAmount); */ + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + /* return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); */ + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/3/SFR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/3/SFR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..86107304622 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/3/SFR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).mul(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).mul(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/3/VVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/3/VVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..30c462bf14a --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/3/VVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 100; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant public constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/4/BOR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/4/BOR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..2e0357c9a1d --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/4/BOR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 + 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] > _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) > minimumUpperThreshold && + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/4/DLR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/4/DLR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..d111da01af8 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/4/DLR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/4/FVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/4/FVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..d435bf77796 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/4/FVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + internal + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + public + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + public + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + public + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/4/ILR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/4/ILR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..c1d019eabae --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/4/ILR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 99; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + uint256 constant BTC_DECIMALS = 7; + uint256 constant ETH_DECIMALS = 17; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/4/SFR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/4/SFR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..5bbeb4eb27a --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/4/SFR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).mul(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).mul(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.add(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/4/VVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/4/VVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..ed08c2ee740 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/4/VVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 100; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant public constant BTC_DECIMALS = 8; + uint256 constant public constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/5/BOR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/5/BOR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..248878e5683 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/5/BOR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 + 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] > _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) > minimumUpperThreshold && + btcDollarAmount.mul(100).div(currentSetDollarAmount) <= maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/5/DLR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/5/DLR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..7beb2b95099 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/5/DLR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] storage assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/5/FVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/5/FVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..ff07cad36f1 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/5/FVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + internal + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + public + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + public + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + public + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + public + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/5/ILR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/5/ILR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..4e58b077f04 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/5/ILR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 99; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + uint256 constant BTC_DECIMALS = 7; + uint256 constant ETH_DECIMALS = 17; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 9 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/5/SFR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/5/SFR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..62c102eab0d --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/5/SFR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).mul(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).mul(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.add(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).mul(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/5/VVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/5/VVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..ac66c4bb157 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/5/VVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 100; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant public constant BTC_DECIMALS = 8; + uint256 constant public constant ETH_DECIMALS = 18; + uint256 constant public constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/6/BOR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/6/BOR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..c9f75323341 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/6/BOR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 + 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] > _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) > minimumUpperThreshold && + btcDollarAmount.mul(100).div(currentSetDollarAmount) <= maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice > _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/6/DLR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/6/DLR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..f65682fac5f --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/6/DLR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] storage assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] storage nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/6/ILR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/6/ILR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..2833accd020 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/6/ILR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 99; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + uint256 constant BTC_DECIMALS = 7; + uint256 constant ETH_DECIMALS = 17; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 9 ** 9; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/6/SFR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/6/SFR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..d27982acfb7 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/6/SFR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).mul(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).mul(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.add(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).mul(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.add(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/6/VVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/6/VVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..3f0df580c5e --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/6/VVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 100; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant public constant BTC_DECIMALS = 8; + uint256 constant public constant ETH_DECIMALS = 18; + uint256 constant public constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address internal btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/7/BOR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/7/BOR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..6b89f4b5729 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/7/BOR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 + 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] > _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) > minimumUpperThreshold && + btcDollarAmount.mul(100).div(currentSetDollarAmount) <= maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice > _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 + 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/7/DLR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/7/DLR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..4982d2176e8 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/7/DLR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] storage assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] storage nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] storage nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/7/ILR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/7/ILR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..aad90b5a26a --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/7/ILR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 99; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + uint256 constant BTC_DECIMALS = 7; + uint256 constant ETH_DECIMALS = 17; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 9 ** 9; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[1] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/7/SFR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/7/SFR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..6f8ea6a8db2 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/7/SFR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).mul(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).mul(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).mul(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.add(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).mul(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.add(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.add(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/7/VVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/7/VVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..d00bb152a13 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/7/VVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 100; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant public constant BTC_DECIMALS = 8; + uint256 constant public constant ETH_DECIMALS = 18; + uint256 constant public constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address internal btcAddress; + address internal ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/8/BOR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/8/BOR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..9c95dbf31e6 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/8/BOR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 + 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] > _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) > minimumUpperThreshold && + btcDollarAmount.mul(100).div(currentSetDollarAmount) <= maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice > _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 + 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 + 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/8/DLR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/8/DLR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..3bf29233bc5 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/8/DLR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] storage assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] storage nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] storage nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] storage) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/8/ILR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/8/ILR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..febf49cecfc --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/8/ILR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 99; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + uint256 constant BTC_DECIMALS = 7; + uint256 constant ETH_DECIMALS = 17; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 9 ** 9; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[1] memory _multipliers, + uint256[1] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/8/VVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/8/VVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..a09c3b1ab7d --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/8/VVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 100; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant public constant BTC_DECIMALS = 8; + uint256 constant public constant ETH_DECIMALS = 18; + uint256 constant public constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address internal btcAddress; + address internal ethAddress; + address internal setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/9/DLR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/9/DLR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..ce61288796f --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/9/DLR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] storage _multipliers, + uint256[2] storage _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] storage currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] storage assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] storage assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] storage nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] storage nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] storage) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] storage nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/9/ILR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/9/ILR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..129435795b1 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/9/ILR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 99; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 999; + uint256 constant BTC_DECIMALS = 7; + uint256 constant ETH_DECIMALS = 17; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 9 ** 9; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[1] memory _multipliers, + uint256[1] memory _allocationBounds + ) + public + { + require( + _allocationBounds[0] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/9/VVR/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/9/VVR/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..1d94a4ec9f2 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/9/VVR/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant public constant PRICE_PRECISION = 100; + uint256 constant public constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant public constant BTC_DECIMALS = 8; + uint256 constant public constant ETH_DECIMALS = 18; + uint256 constant public constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address internal btcAddress; + address internal ethAddress; + address internal setTokenFactory; + + address internal btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCETHRebalancingManager/original/BTCETHRebalancingManager.sol b/contracts/mutants/BTCETHRebalancingManager/original/BTCETHRebalancingManager.sol new file mode 100644 index 00000000000..7236399aa59 --- /dev/null +++ b/contracts/mutants/BTCETHRebalancingManager/original/BTCETHRebalancingManager.sol @@ -0,0 +1,371 @@ +/* + Copyright 2018 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity 0.5.4; +pragma experimental "ABIEncoderV2"; + +import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; +import { ICore } from "../../core/interfaces/ICore.sol"; +import { IMedian } from "../../external/DappHub/interfaces/IMedian.sol"; +import { IRebalancingSetToken } from "../../core/interfaces/IRebalancingSetToken.sol"; +import { ISetToken } from "../../core/interfaces/ISetToken.sol"; +import { RebalancingLibrary } from "../../core/lib/RebalancingLibrary.sol"; +import { ManagerLibrary } from "./lib/ManagerLibrary.sol"; + + +/** + * @title BTCETHRebalancingManager + * @author Set Protocol + * + * Contract used to manage a BTCETH Rebalancing Set Token + */ +contract BTCETHRebalancingManager { + + using SafeMath for uint256; + using AddressArrayUtils for address[]; + + /* ============ Constants ============ */ + + uint256 constant PRICE_PRECISION = 100; + uint256 constant AUCTION_LIB_PRICE_DIVISOR = 1000; + uint256 constant BTC_DECIMALS = 8; + uint256 constant ETH_DECIMALS = 18; + uint256 constant DECIMAL_DIFF_MULTIPLIER = 10 ** 10; + + /* ============ State Variables ============ */ + + address public btcAddress; + address public ethAddress; + address public setTokenFactory; + + address public btcPriceFeed; + address public ethPriceFeed; + + address public coreAddress; + + address public auctionLibrary; + uint256 public auctionTimeToPivot; + uint256 public btcMultiplier; + uint256 public ethMultiplier; + + uint256 public maximumLowerThreshold; + uint256 public minimumUpperThreshold; + + /* ============ Events ============ */ + + event LogManagerProposal( + uint256 btcPrice, + uint256 ethPrice + ); + + /* ============ Constructor ============ */ + + /* + * Rebalancing Token Manager constructor. + * The multipliers are used to calculate the allocation of the set token. Allocation + * is determined by a simple equation: + * btcAllocation = btcMultiplier/(btcMultiplier + ethMultiplier) + * Furthermore the total USD cost of any new Set Token allocation can be found from the + * following equation: + * SetTokenUSDPrice = (btcMultiplier + ethMultiplier)*max(ethPrice, btcPrice) + * + * @param _coreAddress The address of the Core contract + * @param _btcPriceFeedAddress The address of BTC medianizer + * @param _ethPriceFeedAddress The address of ETH medianizer + * @param _btcAddress The address of the wrapped BTC contract + * @param _ethAddress The address of the wrapped ETH contract + * @param _setTokenFactory The address of the SetTokenFactory + * @param _auctionLibrary The address of auction price curve to use in rebalance + * @param _auctionTimeToPivot The amount of time until pivot reached in rebalance + * @param _btcMultiplier With _ethMultiplier, the ratio amount of wbtc to include + * @param _ethMultiplier With _btcMultiplier, the ratio amount of weth to include + */ + constructor( + address _coreAddress, + address _btcPriceFeedAddress, + address _ethPriceFeedAddress, + address _btcAddress, + address _ethAddress, + address _setTokenFactory, + address _auctionLibrary, + uint256 _auctionTimeToPivot, + uint256[2] memory _multipliers, + uint256[2] memory _allocationBounds + ) + public + { + require( + _allocationBounds[1] >= _allocationBounds[0], + "RebalancingTokenManager.constructor: Upper allocation bound must be greater than lower." + ); + + coreAddress = _coreAddress; + + btcPriceFeed = _btcPriceFeedAddress; + ethPriceFeed = _ethPriceFeedAddress; + + btcAddress = _btcAddress; + ethAddress = _ethAddress; + setTokenFactory = _setTokenFactory; + + auctionLibrary = _auctionLibrary; + auctionTimeToPivot = _auctionTimeToPivot; + btcMultiplier = _multipliers[0]; + ethMultiplier = _multipliers[1]; + + maximumLowerThreshold = _allocationBounds[0]; + minimumUpperThreshold = _allocationBounds[1]; + } + + /* ============ External ============ */ + + /* + * When allowed on RebalancingSetToken, anyone can call for a new rebalance proposal + * + * @param _rebalancingSetTokenAddress The address of Rebalancing Set Token to propose new allocation + */ + function propose( + address _rebalancingSetTokenAddress + ) + external + { + // Create interface to interact with RebalancingSetToken + IRebalancingSetToken rebalancingSetInterface = IRebalancingSetToken(_rebalancingSetTokenAddress); + + ManagerLibrary.validateManagerPropose(rebalancingSetInterface); + + // Get price data + uint256 btcPrice = ManagerLibrary.queryPriceData(btcPriceFeed); + uint256 ethPrice = ManagerLibrary.queryPriceData(ethPriceFeed); + + // Require that allocation has changed sufficiently enough to justify rebalance + uint256 currentSetDollarAmount = checkSufficientAllocationChange( + btcPrice, + ethPrice, + rebalancingSetInterface.currentSet() + ); + + // Create new Set Token that collateralizes Rebalancing Set Token + // address nextSetAddress; + ( + address nextSetAddress, + uint256 nextSetDollarAmount + ) = createNewAllocationSetToken( + btcPrice, + ethPrice + ); + + // Calculate the auctionStartPrice and auctionPivotPrice of rebalance auction using dollar value + // of both the current and nextSet + uint256 auctionStartPrice; + uint256 auctionPivotPrice; + ( + auctionStartPrice, + auctionPivotPrice + ) = ManagerLibrary.calculateAuctionPriceParameters( + currentSetDollarAmount, + nextSetDollarAmount, + AUCTION_LIB_PRICE_DIVISOR, + auctionTimeToPivot + ); + + + // Propose new allocation to Rebalancing Set Token + rebalancingSetInterface.propose( + nextSetAddress, + auctionLibrary, + auctionTimeToPivot, + auctionStartPrice, + auctionPivotPrice + ); + + emit LogManagerProposal( + btcPrice, + ethPrice + ); + } + + /* ============ Internal ============ */ + + /* + * Check there has been a sufficient change in allocation (greater than 2%) and return + * USD value of currentSet. + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @param _currentSetAddress The address of the Rebalancing Set Token's currentSet + * @return The currentSet's USD value (in cents) + */ + function checkSufficientAllocationChange( + uint256 _btcPrice, + uint256 _ethPrice, + address _currentSetAddress + ) + private + view + returns (uint256) + { + // Create current set interface + ISetToken currentSetTokenInterface = ISetToken(_currentSetAddress); + + // Get naturalUnit and units of currentSet + uint256 currentSetNaturalUnit = currentSetTokenInterface.naturalUnit(); + uint256[] memory currentSetUnits = currentSetTokenInterface.getUnits(); + + // Calculate wbtc dollar value in currentSet (in cents) + uint256 btcDollarAmount = ManagerLibrary.calculateTokenAllocationAmountUSD( + _btcPrice, + currentSetNaturalUnit, + currentSetUnits[0], + BTC_DECIMALS + ); + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 currentSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + currentSetNaturalUnit, + currentSetUnits, + assetDecimals + ); + + // Require that the allocation has changed more than 2% in order for a rebalance to be called + require( + btcDollarAmount.mul(100).div(currentSetDollarAmount) >= minimumUpperThreshold || + btcDollarAmount.mul(100).div(currentSetDollarAmount) < maximumLowerThreshold, + "RebalancingTokenManager.proposeNewRebalance: Allocation must be further away from 50 percent" + ); + + return currentSetDollarAmount; + } + + /* + * Determine units and naturalUnit of nextSet to propose, calculate auction parameters, and + * create nextSet + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return address The address of nextSet + * @return uint256 The USD value of the nextSet + */ + function createNewAllocationSetToken( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + returns (address, uint256) + { + // Calculate the nextSet units and naturalUnit, determine dollar value of nextSet + uint256 nextSetNaturalUnit; + uint256 nextSetDollarAmount; + uint256[] memory nextSetUnits; + ( + nextSetNaturalUnit, + nextSetDollarAmount, + nextSetUnits + ) = calculateNextSetUnits( + _btcPrice, + _ethPrice + ); + + // Create static components array + address[] memory nextSetComponents = new address[](2); + nextSetComponents[0] = btcAddress; + nextSetComponents[1] = ethAddress; + + // Create the nextSetToken contract that collateralized the Rebalancing Set Token once rebalance + // is finished + address nextSetAddress = ICore(coreAddress).createSet( + setTokenFactory, + nextSetComponents, + nextSetUnits, + nextSetNaturalUnit, + bytes32("BTCETH"), + bytes32("BTCETH"), + "" + ); + + return (nextSetAddress, nextSetDollarAmount); + } + + /* + * Determine units and naturalUnit of nextSet to propose + * + * @param _btcPrice The 18 decimal value of one full BTC + * @param _ethPrice The 18 decimal value of one full ETH + * @return uint256 The naturalUnit of nextSet + * @return uint256 The dollar value of nextSet + * @return uint256[] The units of nextSet + */ + function calculateNextSetUnits( + uint256 _btcPrice, + uint256 _ethPrice + ) + private + view + returns (uint256, uint256, uint256[] memory) + { + // Initialize set token parameters + uint256 nextSetNaturalUnit; + uint256[] memory nextSetUnits = new uint256[](2); + + if (_btcPrice >= _ethPrice) { + // Calculate ethereum nextSetUnits, determined by the following equation: + // (btcPrice / ethPrice) * (10 ** (ethDecimal - btcDecimal)) + uint256 ethUnits = _btcPrice.mul(DECIMAL_DIFF_MULTIPLIER).div(_ethPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = btcMultiplier; + nextSetUnits[1] = ethUnits.mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 10; + } else { + // Calculate btc nextSetUnits as (ethPrice / btcPrice) * 100. 100 is used to add + // precision. The increase in unit amounts is offset by increasing the + // nextSetNaturalUnit by two orders of magnitude so that issuance cost is still + // roughly the same + uint256 ethBtcPrice = _ethPrice.mul(PRICE_PRECISION).div(_btcPrice); + + // Create unit array and define natural unit + nextSetUnits[0] = ethBtcPrice.mul(btcMultiplier); + nextSetUnits[1] = PRICE_PRECISION.mul(DECIMAL_DIFF_MULTIPLIER).mul(ethMultiplier); + nextSetNaturalUnit = 10 ** 12; + } + + uint256[] memory assetPrices = new uint256[](2); + assetPrices[0] = _btcPrice; + assetPrices[1] = _ethPrice; + + uint256[] memory assetDecimals = new uint256[](2); + assetDecimals[0] = BTC_DECIMALS; + assetDecimals[1] = ETH_DECIMALS; + + uint256 nextSetDollarAmount = ManagerLibrary.calculateSetTokenDollarValue( + assetPrices, + nextSetNaturalUnit, + nextSetUnits, + assetDecimals + ); + + return (nextSetNaturalUnit, nextSetDollarAmount, nextSetUnits); + } +} diff --git a/contracts/mutants/BTCMintVault/1/ORFD/BTCMintVault.sol b/contracts/mutants/BTCMintVault/1/ORFD/BTCMintVault.sol new file mode 100644 index 00000000000..8156d9bdd7a --- /dev/null +++ b/contracts/mutants/BTCMintVault/1/ORFD/BTCMintVault.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.9; + +import "./MintVault.sol"; + +contract BTCMintVault is MintVault { + +// TODO: 不同的dAsset 可以可能有不同的实现mint。 + + +} \ No newline at end of file diff --git a/contracts/mutants/BTCMintVault/original/BTCMintVault.sol b/contracts/mutants/BTCMintVault/original/BTCMintVault.sol new file mode 100644 index 00000000000..231ea28bb53 --- /dev/null +++ b/contracts/mutants/BTCMintVault/original/BTCMintVault.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.9; + +import "./MintVault.sol"; + +contract BTCMintVault is MintVault { + +// TODO: 不同的dAsset 可以可能有不同的实现mint。 + function underlyingBurn(uint amount) internal virtual override { + IDUSD(underlying).burnme(amount); + } + +} \ No newline at end of file diff --git a/contracts/mutants/BToken/1/BLR/BToken.sol b/contracts/mutants/BToken/1/BLR/BToken.sol new file mode 100644 index 00000000000..f5905a48b13 --- /dev/null +++ b/contracts/mutants/BToken/1/BLR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return false; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/1/BOR/BToken.sol b/contracts/mutants/BToken/1/BOR/BToken.sol new file mode 100644 index 00000000000..1014697ab16 --- /dev/null +++ b/contracts/mutants/BToken/1/BOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/1/CSC/BToken.sol b/contracts/mutants/BToken/1/CSC/BToken.sol new file mode 100644 index 00000000000..a3d029d4230 --- /dev/null +++ b/contracts/mutants/BToken/1/CSC/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (true) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/1/DLR/BToken.sol b/contracts/mutants/BToken/1/DLR/BToken.sol new file mode 100644 index 00000000000..41b569aa9d2 --- /dev/null +++ b/contracts/mutants/BToken/1/DLR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string storage) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/1/ECS/BToken.sol b/contracts/mutants/BToken/1/ECS/BToken.sol new file mode 100644 index 00000000000..16b39236b82 --- /dev/null +++ b/contracts/mutants/BToken/1/ECS/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint8(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/1/EED/BToken.sol b/contracts/mutants/BToken/1/EED/BToken.sol new file mode 100644 index 00000000000..3c1d23a9dde --- /dev/null +++ b/contracts/mutants/BToken/1/EED/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + /* emit Transfer(address(0), address(this), amt); */ + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/1/EHC/BToken.sol b/contracts/mutants/BToken/1/EHC/BToken.sol new file mode 100644 index 00000000000..80ccc870147 --- /dev/null +++ b/contracts/mutants/BToken/1/EHC/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + /* require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); */ + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/1/FVR/BToken.sol b/contracts/mutants/BToken/1/FVR/BToken.sol new file mode 100644 index 00000000000..9158bdf8019 --- /dev/null +++ b/contracts/mutants/BToken/1/FVR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) public { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/1/ILR/BToken.sol b/contracts/mutants/BToken/1/ILR/BToken.sol new file mode 100644 index 00000000000..99abfea410d --- /dev/null +++ b/contracts/mutants/BToken/1/ILR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(1), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/1/OLFD/BToken.sol b/contracts/mutants/BToken/1/OLFD/BToken.sol new file mode 100644 index 00000000000..e3c624775cd --- /dev/null +++ b/contracts/mutants/BToken/1/OLFD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/1/RSD/BToken.sol b/contracts/mutants/BToken/1/RSD/BToken.sol new file mode 100644 index 00000000000..10d291ad45e --- /dev/null +++ b/contracts/mutants/BToken/1/RSD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + /* return _name; */ + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/1/SLR/BToken.sol b/contracts/mutants/BToken/1/SLR/BToken.sol new file mode 100644 index 00000000000..f9066174614 --- /dev/null +++ b/contracts/mutants/BToken/1/SLR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = ""; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/1/TOR/BToken.sol b/contracts/mutants/BToken/1/TOR/BToken.sol new file mode 100644 index 00000000000..43f587952fd --- /dev/null +++ b/contracts/mutants/BToken/1/TOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/1/UORD/BToken.sol b/contracts/mutants/BToken/1/UORD/BToken.sol new file mode 100644 index 00000000000..998e30346ac --- /dev/null +++ b/contracts/mutants/BToken/1/UORD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256( 1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/1/VVR/BToken.sol b/contracts/mutants/BToken/1/VVR/BToken.sol new file mode 100644 index 00000000000..f058540caa8 --- /dev/null +++ b/contracts/mutants/BToken/1/VVR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint public _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/10/FVR/BToken.sol b/contracts/mutants/BToken/10/FVR/BToken.sol new file mode 100644 index 00000000000..74222d6a424 --- /dev/null +++ b/contracts/mutants/BToken/10/FVR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) public { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) public { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) public { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) public { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) public { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() external view returns (string memory) { + return _name; + } + + function symbol() external view returns (string memory) { + return _symbol; + } + + function decimals() external view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) public view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) public view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/10/OLFD/BToken.sol b/contracts/mutants/BToken/10/OLFD/BToken.sol new file mode 100644 index 00000000000..5d09f807ff1 --- /dev/null +++ b/contracts/mutants/BToken/10/OLFD/BToken.sol @@ -0,0 +1,129 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + + + + + + + +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + + + + + + + + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/10/RSD/BToken.sol b/contracts/mutants/BToken/10/RSD/BToken.sol new file mode 100644 index 00000000000..64d842c813d --- /dev/null +++ b/contracts/mutants/BToken/10/RSD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + /* return _name; */ + } + + function symbol() public view returns (string memory) { + /* return _symbol; */ + } + + function decimals() public view returns(uint8) { + /* return _decimals; */ + } + + function allowance(address src, address dst) external view returns (uint) { + /* return _allowance[src][dst]; */ + } + + function balanceOf(address whom) external view returns (uint) { + /* return _balance[whom]; */ + } + + function totalSupply() public view returns (uint) { + /* return _totalSupply; */ + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + /* return true; */ + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + /* return true; */ + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + /* return true; */ + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + /* return true; */ + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/10/TOR/BToken.sol b/contracts/mutants/BToken/10/TOR/BToken.sol new file mode 100644 index 00000000000..f216a04df1a --- /dev/null +++ b/contracts/mutants/BToken/10/TOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = amt; + emit Approval(tx.origin, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = badd(_allowance[tx.origin][dst], amt); + emit Approval(tx.origin, dst, _allowance[tx.origin][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[tx.origin][dst]; + if (amt > oldValue) { + _allowance[tx.origin][dst] = 0; + } else { + _allowance[tx.origin][dst] = bsub(oldValue, amt); + } + emit Approval(tx.origin, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/2/BLR/BToken.sol b/contracts/mutants/BToken/2/BLR/BToken.sol new file mode 100644 index 00000000000..352ad2e4d1a --- /dev/null +++ b/contracts/mutants/BToken/2/BLR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return false; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return false; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/2/BOR/BToken.sol b/contracts/mutants/BToken/2/BOR/BToken.sol new file mode 100644 index 00000000000..d2fffb7c208 --- /dev/null +++ b/contracts/mutants/BToken/2/BOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/2/CSC/BToken.sol b/contracts/mutants/BToken/2/CSC/BToken.sol new file mode 100644 index 00000000000..9e68eb46638 --- /dev/null +++ b/contracts/mutants/BToken/2/CSC/BToken.sol @@ -0,0 +1,139 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (true) { + _allowance[msg.sender][dst] = 0; + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/2/DLR/BToken.sol b/contracts/mutants/BToken/2/DLR/BToken.sol new file mode 100644 index 00000000000..975efa6f905 --- /dev/null +++ b/contracts/mutants/BToken/2/DLR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string storage) { + return _name; + } + + function symbol() public view returns (string storage) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/2/EED/BToken.sol b/contracts/mutants/BToken/2/EED/BToken.sol new file mode 100644 index 00000000000..401b31e71d4 --- /dev/null +++ b/contracts/mutants/BToken/2/EED/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + /* emit Transfer(address(0), address(this), amt); */ + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + /* emit Transfer(address(this), address(0), amt); */ + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/2/EHC/BToken.sol b/contracts/mutants/BToken/2/EHC/BToken.sol new file mode 100644 index 00000000000..2bd0ce41876 --- /dev/null +++ b/contracts/mutants/BToken/2/EHC/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + /* require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); */ + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + /* require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); */ + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/2/FVR/BToken.sol b/contracts/mutants/BToken/2/FVR/BToken.sol new file mode 100644 index 00000000000..44427bbd047 --- /dev/null +++ b/contracts/mutants/BToken/2/FVR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) public { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) public { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/2/ILR/BToken.sol b/contracts/mutants/BToken/2/ILR/BToken.sol new file mode 100644 index 00000000000..389ed57bcdc --- /dev/null +++ b/contracts/mutants/BToken/2/ILR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(1), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(1), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/2/OLFD/BToken.sol b/contracts/mutants/BToken/2/OLFD/BToken.sol new file mode 100644 index 00000000000..fd69af4436b --- /dev/null +++ b/contracts/mutants/BToken/2/OLFD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + + + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/2/RSD/BToken.sol b/contracts/mutants/BToken/2/RSD/BToken.sol new file mode 100644 index 00000000000..8a88a1593fb --- /dev/null +++ b/contracts/mutants/BToken/2/RSD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + /* return _name; */ + } + + function symbol() public view returns (string memory) { + /* return _symbol; */ + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/2/SLR/BToken.sol b/contracts/mutants/BToken/2/SLR/BToken.sol new file mode 100644 index 00000000000..faf9f926730 --- /dev/null +++ b/contracts/mutants/BToken/2/SLR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = ""; + string private _symbol = ""; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/2/TOR/BToken.sol b/contracts/mutants/BToken/2/TOR/BToken.sol new file mode 100644 index 00000000000..ba2eb687f62 --- /dev/null +++ b/contracts/mutants/BToken/2/TOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = amt; + emit Approval(tx.origin, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/2/VVR/BToken.sol b/contracts/mutants/BToken/2/VVR/BToken.sol new file mode 100644 index 00000000000..b738448bda7 --- /dev/null +++ b/contracts/mutants/BToken/2/VVR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint public _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string public _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/3/BLR/BToken.sol b/contracts/mutants/BToken/3/BLR/BToken.sol new file mode 100644 index 00000000000..5f88c564e52 --- /dev/null +++ b/contracts/mutants/BToken/3/BLR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return false; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return false; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return false; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/3/BOR/BToken.sol b/contracts/mutants/BToken/3/BOR/BToken.sol new file mode 100644 index 00000000000..a856a86ebb4 --- /dev/null +++ b/contracts/mutants/BToken/3/BOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt >= oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/3/CSC/BToken.sol b/contracts/mutants/BToken/3/CSC/BToken.sol new file mode 100644 index 00000000000..b6913a9a3d6 --- /dev/null +++ b/contracts/mutants/BToken/3/CSC/BToken.sol @@ -0,0 +1,139 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (true) { + _allowance[msg.sender][dst] = 0; + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (true) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/3/EED/BToken.sol b/contracts/mutants/BToken/3/EED/BToken.sol new file mode 100644 index 00000000000..7e284c4a343 --- /dev/null +++ b/contracts/mutants/BToken/3/EED/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + /* emit Transfer(address(0), address(this), amt); */ + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + /* emit Transfer(address(this), address(0), amt); */ + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + /* emit Transfer(src, dst, amt); */ + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/3/EHC/BToken.sol b/contracts/mutants/BToken/3/EHC/BToken.sol new file mode 100644 index 00000000000..b020bbcbbe3 --- /dev/null +++ b/contracts/mutants/BToken/3/EHC/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + /* require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); */ + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + /* require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); */ + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + /* require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); */ + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/3/FVR/BToken.sol b/contracts/mutants/BToken/3/FVR/BToken.sol new file mode 100644 index 00000000000..86a26e6223b --- /dev/null +++ b/contracts/mutants/BToken/3/FVR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) public { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) public { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) public { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/3/ILR/BToken.sol b/contracts/mutants/BToken/3/ILR/BToken.sol new file mode 100644 index 00000000000..642b6b1fe8b --- /dev/null +++ b/contracts/mutants/BToken/3/ILR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(1), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(1), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 17; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/3/OLFD/BToken.sol b/contracts/mutants/BToken/3/OLFD/BToken.sol new file mode 100644 index 00000000000..a6fcde4446b --- /dev/null +++ b/contracts/mutants/BToken/3/OLFD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + + + + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/3/RSD/BToken.sol b/contracts/mutants/BToken/3/RSD/BToken.sol new file mode 100644 index 00000000000..fcca182962c --- /dev/null +++ b/contracts/mutants/BToken/3/RSD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + /* return _name; */ + } + + function symbol() public view returns (string memory) { + /* return _symbol; */ + } + + function decimals() public view returns(uint8) { + /* return _decimals; */ + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/3/TOR/BToken.sol b/contracts/mutants/BToken/3/TOR/BToken.sol new file mode 100644 index 00000000000..16d5d1158c8 --- /dev/null +++ b/contracts/mutants/BToken/3/TOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = amt; + emit Approval(tx.origin, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/3/VVR/BToken.sol b/contracts/mutants/BToken/3/VVR/BToken.sol new file mode 100644 index 00000000000..76dbe632dbe --- /dev/null +++ b/contracts/mutants/BToken/3/VVR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint public _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string public _name = "Balancer Pool Token"; + string public _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/4/BLR/BToken.sol b/contracts/mutants/BToken/4/BLR/BToken.sol new file mode 100644 index 00000000000..94e77ce9658 --- /dev/null +++ b/contracts/mutants/BToken/4/BLR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return false; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return false; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return false; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return false; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/4/BOR/BToken.sol b/contracts/mutants/BToken/4/BOR/BToken.sol new file mode 100644 index 00000000000..f03b56446c4 --- /dev/null +++ b/contracts/mutants/BToken/4/BOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt >= oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender <= src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/4/EED/BToken.sol b/contracts/mutants/BToken/4/EED/BToken.sol new file mode 100644 index 00000000000..41ab2b70e22 --- /dev/null +++ b/contracts/mutants/BToken/4/EED/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + /* emit Transfer(address(0), address(this), amt); */ + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + /* emit Transfer(address(this), address(0), amt); */ + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + /* emit Transfer(src, dst, amt); */ + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + /* emit Approval(msg.sender, dst, amt); */ + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/4/FVR/BToken.sol b/contracts/mutants/BToken/4/FVR/BToken.sol new file mode 100644 index 00000000000..0a8a8653533 --- /dev/null +++ b/contracts/mutants/BToken/4/FVR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) public { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) public { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) public { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) public { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/4/ILR/BToken.sol b/contracts/mutants/BToken/4/ILR/BToken.sol new file mode 100644 index 00000000000..95b4d013850 --- /dev/null +++ b/contracts/mutants/BToken/4/ILR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(1), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(1), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 17; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 1; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/4/OLFD/BToken.sol b/contracts/mutants/BToken/4/OLFD/BToken.sol new file mode 100644 index 00000000000..7a897e2b50b --- /dev/null +++ b/contracts/mutants/BToken/4/OLFD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + + + + + + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/4/RSD/BToken.sol b/contracts/mutants/BToken/4/RSD/BToken.sol new file mode 100644 index 00000000000..69cd3752c0b --- /dev/null +++ b/contracts/mutants/BToken/4/RSD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + /* return _name; */ + } + + function symbol() public view returns (string memory) { + /* return _symbol; */ + } + + function decimals() public view returns(uint8) { + /* return _decimals; */ + } + + function allowance(address src, address dst) external view returns (uint) { + /* return _allowance[src][dst]; */ + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/4/TOR/BToken.sol b/contracts/mutants/BToken/4/TOR/BToken.sol new file mode 100644 index 00000000000..6ad0ce38ec8 --- /dev/null +++ b/contracts/mutants/BToken/4/TOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = amt; + emit Approval(tx.origin, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = badd(_allowance[tx.origin][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/4/VVR/BToken.sol b/contracts/mutants/BToken/4/VVR/BToken.sol new file mode 100644 index 00000000000..3f689575741 --- /dev/null +++ b/contracts/mutants/BToken/4/VVR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint public _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string public _name = "Balancer Pool Token"; + string public _symbol = "BPT"; + uint8 public _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/5/BLR/BToken.sol b/contracts/mutants/BToken/5/BLR/BToken.sol new file mode 100644 index 00000000000..da91d789f75 --- /dev/null +++ b/contracts/mutants/BToken/5/BLR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return false; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return false; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return false; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return false; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return false; + } +} + diff --git a/contracts/mutants/BToken/5/BOR/BToken.sol b/contracts/mutants/BToken/5/BOR/BToken.sol new file mode 100644 index 00000000000..c5ee3da0b3e --- /dev/null +++ b/contracts/mutants/BToken/5/BOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt >= oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender <= src && amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/5/EED/BToken.sol b/contracts/mutants/BToken/5/EED/BToken.sol new file mode 100644 index 00000000000..39e2dfdaeb0 --- /dev/null +++ b/contracts/mutants/BToken/5/EED/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + /* emit Transfer(address(0), address(this), amt); */ + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + /* emit Transfer(address(this), address(0), amt); */ + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + /* emit Transfer(src, dst, amt); */ + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + /* emit Approval(msg.sender, dst, amt); */ + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + /* emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); */ + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/5/FVR/BToken.sol b/contracts/mutants/BToken/5/FVR/BToken.sol new file mode 100644 index 00000000000..177f07022ab --- /dev/null +++ b/contracts/mutants/BToken/5/FVR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) public { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) public { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) public { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) public { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) public { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/5/ILR/BToken.sol b/contracts/mutants/BToken/5/ILR/BToken.sol new file mode 100644 index 00000000000..9909dd4c0a3 --- /dev/null +++ b/contracts/mutants/BToken/5/ILR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(1), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(1), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 17; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 1; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(0)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/5/OLFD/BToken.sol b/contracts/mutants/BToken/5/OLFD/BToken.sol new file mode 100644 index 00000000000..fc3ddcbb2d5 --- /dev/null +++ b/contracts/mutants/BToken/5/OLFD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + + + + + + + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/5/RSD/BToken.sol b/contracts/mutants/BToken/5/RSD/BToken.sol new file mode 100644 index 00000000000..085721a51c4 --- /dev/null +++ b/contracts/mutants/BToken/5/RSD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + /* return _name; */ + } + + function symbol() public view returns (string memory) { + /* return _symbol; */ + } + + function decimals() public view returns(uint8) { + /* return _decimals; */ + } + + function allowance(address src, address dst) external view returns (uint) { + /* return _allowance[src][dst]; */ + } + + function balanceOf(address whom) external view returns (uint) { + /* return _balance[whom]; */ + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/5/TOR/BToken.sol b/contracts/mutants/BToken/5/TOR/BToken.sol new file mode 100644 index 00000000000..b2076f9817a --- /dev/null +++ b/contracts/mutants/BToken/5/TOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = amt; + emit Approval(tx.origin, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = badd(_allowance[tx.origin][dst], amt); + emit Approval(tx.origin, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/6/BOR/BToken.sol b/contracts/mutants/BToken/6/BOR/BToken.sol new file mode 100644 index 00000000000..a1c8a274efb --- /dev/null +++ b/contracts/mutants/BToken/6/BOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt >= oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender <= src && amt < _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/6/EED/BToken.sol b/contracts/mutants/BToken/6/EED/BToken.sol new file mode 100644 index 00000000000..5768545851f --- /dev/null +++ b/contracts/mutants/BToken/6/EED/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + /* emit Transfer(address(0), address(this), amt); */ + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + /* emit Transfer(address(this), address(0), amt); */ + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + /* emit Transfer(src, dst, amt); */ + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + /* emit Approval(msg.sender, dst, amt); */ + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + /* emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); */ + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + /* emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); */ + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/6/FVR/BToken.sol b/contracts/mutants/BToken/6/FVR/BToken.sol new file mode 100644 index 00000000000..92f9b7766a8 --- /dev/null +++ b/contracts/mutants/BToken/6/FVR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) public { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) public { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) public { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) public { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) public { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() external view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/6/OLFD/BToken.sol b/contracts/mutants/BToken/6/OLFD/BToken.sol new file mode 100644 index 00000000000..2afc1ea22e9 --- /dev/null +++ b/contracts/mutants/BToken/6/OLFD/BToken.sol @@ -0,0 +1,139 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + + + + + + + +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/6/RSD/BToken.sol b/contracts/mutants/BToken/6/RSD/BToken.sol new file mode 100644 index 00000000000..6dc38d07d6f --- /dev/null +++ b/contracts/mutants/BToken/6/RSD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + /* return _name; */ + } + + function symbol() public view returns (string memory) { + /* return _symbol; */ + } + + function decimals() public view returns(uint8) { + /* return _decimals; */ + } + + function allowance(address src, address dst) external view returns (uint) { + /* return _allowance[src][dst]; */ + } + + function balanceOf(address whom) external view returns (uint) { + /* return _balance[whom]; */ + } + + function totalSupply() public view returns (uint) { + /* return _totalSupply; */ + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/6/TOR/BToken.sol b/contracts/mutants/BToken/6/TOR/BToken.sol new file mode 100644 index 00000000000..d5a08e856bc --- /dev/null +++ b/contracts/mutants/BToken/6/TOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = amt; + emit Approval(tx.origin, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = badd(_allowance[tx.origin][dst], amt); + emit Approval(tx.origin, dst, _allowance[tx.origin][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/7/BOR/BToken.sol b/contracts/mutants/BToken/7/BOR/BToken.sol new file mode 100644 index 00000000000..373b8c4dd8f --- /dev/null +++ b/contracts/mutants/BToken/7/BOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt >= oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender <= src && amt < _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender > src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/7/EED/BToken.sol b/contracts/mutants/BToken/7/EED/BToken.sol new file mode 100644 index 00000000000..b491f1ecdfc --- /dev/null +++ b/contracts/mutants/BToken/7/EED/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + /* emit Transfer(address(0), address(this), amt); */ + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + /* emit Transfer(address(this), address(0), amt); */ + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + /* emit Transfer(src, dst, amt); */ + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + /* emit Approval(msg.sender, dst, amt); */ + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + /* emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); */ + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + /* emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); */ + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + /* emit Approval(msg.sender, dst, _allowance[src][msg.sender]); */ + } + return true; + } +} + diff --git a/contracts/mutants/BToken/7/FVR/BToken.sol b/contracts/mutants/BToken/7/FVR/BToken.sol new file mode 100644 index 00000000000..5b847059988 --- /dev/null +++ b/contracts/mutants/BToken/7/FVR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) public { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) public { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) public { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) public { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) public { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() external view returns (string memory) { + return _name; + } + + function symbol() external view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/7/OLFD/BToken.sol b/contracts/mutants/BToken/7/OLFD/BToken.sol new file mode 100644 index 00000000000..4b78c63ba41 --- /dev/null +++ b/contracts/mutants/BToken/7/OLFD/BToken.sol @@ -0,0 +1,137 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + + + + + + + +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/7/RSD/BToken.sol b/contracts/mutants/BToken/7/RSD/BToken.sol new file mode 100644 index 00000000000..051228b1ecc --- /dev/null +++ b/contracts/mutants/BToken/7/RSD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + /* return _name; */ + } + + function symbol() public view returns (string memory) { + /* return _symbol; */ + } + + function decimals() public view returns(uint8) { + /* return _decimals; */ + } + + function allowance(address src, address dst) external view returns (uint) { + /* return _allowance[src][dst]; */ + } + + function balanceOf(address whom) external view returns (uint) { + /* return _balance[whom]; */ + } + + function totalSupply() public view returns (uint) { + /* return _totalSupply; */ + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + /* return true; */ + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/7/TOR/BToken.sol b/contracts/mutants/BToken/7/TOR/BToken.sol new file mode 100644 index 00000000000..e9a661cf913 --- /dev/null +++ b/contracts/mutants/BToken/7/TOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = amt; + emit Approval(tx.origin, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = badd(_allowance[tx.origin][dst], amt); + emit Approval(tx.origin, dst, _allowance[tx.origin][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[tx.origin][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/8/BOR/BToken.sol b/contracts/mutants/BToken/8/BOR/BToken.sol new file mode 100644 index 00000000000..5d2ad9c0c5d --- /dev/null +++ b/contracts/mutants/BToken/8/BOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt >= oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender <= src && amt < _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender > src || _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/8/FVR/BToken.sol b/contracts/mutants/BToken/8/FVR/BToken.sol new file mode 100644 index 00000000000..18df0e1808a --- /dev/null +++ b/contracts/mutants/BToken/8/FVR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) public { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) public { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) public { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) public { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) public { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() external view returns (string memory) { + return _name; + } + + function symbol() external view returns (string memory) { + return _symbol; + } + + function decimals() external view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/8/OLFD/BToken.sol b/contracts/mutants/BToken/8/OLFD/BToken.sol new file mode 100644 index 00000000000..1af7a854783 --- /dev/null +++ b/contracts/mutants/BToken/8/OLFD/BToken.sol @@ -0,0 +1,135 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + + + + + + + +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + + + + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/8/RSD/BToken.sol b/contracts/mutants/BToken/8/RSD/BToken.sol new file mode 100644 index 00000000000..118c43b538d --- /dev/null +++ b/contracts/mutants/BToken/8/RSD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + /* return _name; */ + } + + function symbol() public view returns (string memory) { + /* return _symbol; */ + } + + function decimals() public view returns(uint8) { + /* return _decimals; */ + } + + function allowance(address src, address dst) external view returns (uint) { + /* return _allowance[src][dst]; */ + } + + function balanceOf(address whom) external view returns (uint) { + /* return _balance[whom]; */ + } + + function totalSupply() public view returns (uint) { + /* return _totalSupply; */ + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + /* return true; */ + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + /* return true; */ + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/8/TOR/BToken.sol b/contracts/mutants/BToken/8/TOR/BToken.sol new file mode 100644 index 00000000000..4a262a10e14 --- /dev/null +++ b/contracts/mutants/BToken/8/TOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = amt; + emit Approval(tx.origin, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = badd(_allowance[tx.origin][dst], amt); + emit Approval(tx.origin, dst, _allowance[tx.origin][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[tx.origin][dst]; + if (amt > oldValue) { + _allowance[tx.origin][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/9/BOR/BToken.sol b/contracts/mutants/BToken/9/BOR/BToken.sol new file mode 100644 index 00000000000..b17f9e1967a --- /dev/null +++ b/contracts/mutants/BToken/9/BOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] > amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt >= oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender <= src && amt < _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender > src || _allowance[src][msg.sender] > uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/9/FVR/BToken.sol b/contracts/mutants/BToken/9/FVR/BToken.sol new file mode 100644 index 00000000000..274b28538b4 --- /dev/null +++ b/contracts/mutants/BToken/9/FVR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) public { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) public { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) public { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) public { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) public { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() external view returns (string memory) { + return _name; + } + + function symbol() external view returns (string memory) { + return _symbol; + } + + function decimals() external view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) public view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/9/OLFD/BToken.sol b/contracts/mutants/BToken/9/OLFD/BToken.sol new file mode 100644 index 00000000000..1045b4b05d9 --- /dev/null +++ b/contracts/mutants/BToken/9/OLFD/BToken.sol @@ -0,0 +1,133 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + + + + + + + +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + + + + + + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/9/RSD/BToken.sol b/contracts/mutants/BToken/9/RSD/BToken.sol new file mode 100644 index 00000000000..d7fa9769b44 --- /dev/null +++ b/contracts/mutants/BToken/9/RSD/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + /* return _name; */ + } + + function symbol() public view returns (string memory) { + /* return _symbol; */ + } + + function decimals() public view returns(uint8) { + /* return _decimals; */ + } + + function allowance(address src, address dst) external view returns (uint) { + /* return _allowance[src][dst]; */ + } + + function balanceOf(address whom) external view returns (uint) { + /* return _balance[whom]; */ + } + + function totalSupply() public view returns (uint) { + /* return _totalSupply; */ + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + /* return true; */ + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + /* return true; */ + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + /* return true; */ + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/9/TOR/BToken.sol b/contracts/mutants/BToken/9/TOR/BToken.sol new file mode 100644 index 00000000000..cce686f3069 --- /dev/null +++ b/contracts/mutants/BToken/9/TOR/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = amt; + emit Approval(tx.origin, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[tx.origin][dst] = badd(_allowance[tx.origin][dst], amt); + emit Approval(tx.origin, dst, _allowance[tx.origin][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[tx.origin][dst]; + if (amt > oldValue) { + _allowance[tx.origin][dst] = 0; + } else { + _allowance[tx.origin][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BToken/original/BToken.sol b/contracts/mutants/BToken/original/BToken.sol new file mode 100644 index 00000000000..07cbfe488b7 --- /dev/null +++ b/contracts/mutants/BToken/original/BToken.sol @@ -0,0 +1,141 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity 0.5.12; + +import "./BNum.sol"; + +// Highly opinionated token implementation + +interface IERC20 { + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function totalSupply() external view returns (uint); + function balanceOf(address whom) external view returns (uint); + function allowance(address src, address dst) external view returns (uint); + + function approve(address dst, uint amt) external returns (bool); + function transfer(address dst, uint amt) external returns (bool); + function transferFrom( + address src, address dst, uint amt + ) external returns (bool); +} + +contract BTokenBase is BNum { + + mapping(address => uint) internal _balance; + mapping(address => mapping(address=>uint)) internal _allowance; + uint internal _totalSupply; + + event Approval(address indexed src, address indexed dst, uint amt); + event Transfer(address indexed src, address indexed dst, uint amt); + + function _mint(uint amt) internal { + _balance[address(this)] = badd(_balance[address(this)], amt); + _totalSupply = badd(_totalSupply, amt); + emit Transfer(address(0), address(this), amt); + } + + function _burn(uint amt) internal { + require(_balance[address(this)] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[address(this)] = bsub(_balance[address(this)], amt); + _totalSupply = bsub(_totalSupply, amt); + emit Transfer(address(this), address(0), amt); + } + + function _move(address src, address dst, uint amt) internal { + require(_balance[src] >= amt, "ERR_INSUFFICIENT_BAL"); + _balance[src] = bsub(_balance[src], amt); + _balance[dst] = badd(_balance[dst], amt); + emit Transfer(src, dst, amt); + } + + function _push(address to, uint amt) internal { + _move(address(this), to, amt); + } + + function _pull(address from, uint amt) internal { + _move(from, address(this), amt); + } +} + +contract BToken is BTokenBase, IERC20 { + + string private _name = "Balancer Pool Token"; + string private _symbol = "BPT"; + uint8 private _decimals = 18; + + function name() public view returns (string memory) { + return _name; + } + + function symbol() public view returns (string memory) { + return _symbol; + } + + function decimals() public view returns(uint8) { + return _decimals; + } + + function allowance(address src, address dst) external view returns (uint) { + return _allowance[src][dst]; + } + + function balanceOf(address whom) external view returns (uint) { + return _balance[whom]; + } + + function totalSupply() public view returns (uint) { + return _totalSupply; + } + + function approve(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = amt; + emit Approval(msg.sender, dst, amt); + return true; + } + + function increaseApproval(address dst, uint amt) external returns (bool) { + _allowance[msg.sender][dst] = badd(_allowance[msg.sender][dst], amt); + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function decreaseApproval(address dst, uint amt) external returns (bool) { + uint oldValue = _allowance[msg.sender][dst]; + if (amt > oldValue) { + _allowance[msg.sender][dst] = 0; + } else { + _allowance[msg.sender][dst] = bsub(oldValue, amt); + } + emit Approval(msg.sender, dst, _allowance[msg.sender][dst]); + return true; + } + + function transfer(address dst, uint amt) external returns (bool) { + _move(msg.sender, dst, amt); + return true; + } + + function transferFrom(address src, address dst, uint amt) external returns (bool) { + require(msg.sender == src || amt <= _allowance[src][msg.sender], "ERR_BTOKEN_BAD_CALLER"); + _move(src, dst, amt); + if (msg.sender != src && _allowance[src][msg.sender] != uint256(-1)) { + _allowance[src][msg.sender] = bsub(_allowance[src][msg.sender], amt); + emit Approval(msg.sender, dst, _allowance[src][msg.sender]); + } + return true; + } +} + diff --git a/contracts/mutants/BUSDV2CurveConvex/1/CCD/BUSDV2CurveConvex.sol b/contracts/mutants/BUSDV2CurveConvex/1/CCD/BUSDV2CurveConvex.sol new file mode 100644 index 00000000000..c51fe6f4b1c --- /dev/null +++ b/contracts/mutants/BUSDV2CurveConvex/1/CCD/BUSDV2CurveConvex.sol @@ -0,0 +1,9 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.8.4; + +import "../utils/Constants.sol"; +import "./BaseCurveConvex2.sol"; + +contract BUSDV2CurveConvex is BaseCurveConvex2 { + +} diff --git a/contracts/mutants/BUSDV2CurveConvex/1/ILR/BUSDV2CurveConvex.sol b/contracts/mutants/BUSDV2CurveConvex/1/ILR/BUSDV2CurveConvex.sol new file mode 100644 index 00000000000..0e61b91d008 --- /dev/null +++ b/contracts/mutants/BUSDV2CurveConvex/1/ILR/BUSDV2CurveConvex.sol @@ -0,0 +1,20 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.8.4; + +import "../utils/Constants.sol"; +import "./BaseCurveConvex2.sol"; + +contract BUSDV2CurveConvex is BaseCurveConvex2 { + constructor() + BaseCurveConvex2( + Constants.CRV_BUSDV2_ADDRESS, + Constants.CRV_BUSDV2_LP_ADDRESS, + Constants.CVX_BUSDV2_REWARDS_ADDRESS, + Constants.CVX_BUSDV2_PID, + Constants.BUSD_ADDRESS, + address(1), + address(0), + address(0) + ) + {} +} diff --git a/contracts/mutants/BUSDV2CurveConvex/2/ILR/BUSDV2CurveConvex.sol b/contracts/mutants/BUSDV2CurveConvex/2/ILR/BUSDV2CurveConvex.sol new file mode 100644 index 00000000000..810515483c3 --- /dev/null +++ b/contracts/mutants/BUSDV2CurveConvex/2/ILR/BUSDV2CurveConvex.sol @@ -0,0 +1,20 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.8.4; + +import "../utils/Constants.sol"; +import "./BaseCurveConvex2.sol"; + +contract BUSDV2CurveConvex is BaseCurveConvex2 { + constructor() + BaseCurveConvex2( + Constants.CRV_BUSDV2_ADDRESS, + Constants.CRV_BUSDV2_LP_ADDRESS, + Constants.CVX_BUSDV2_REWARDS_ADDRESS, + Constants.CVX_BUSDV2_PID, + Constants.BUSD_ADDRESS, + address(1), + address(1), + address(0) + ) + {} +} diff --git a/contracts/mutants/BUSDV2CurveConvex/3/ILR/BUSDV2CurveConvex.sol b/contracts/mutants/BUSDV2CurveConvex/3/ILR/BUSDV2CurveConvex.sol new file mode 100644 index 00000000000..5e7270006b2 --- /dev/null +++ b/contracts/mutants/BUSDV2CurveConvex/3/ILR/BUSDV2CurveConvex.sol @@ -0,0 +1,20 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.8.4; + +import "../utils/Constants.sol"; +import "./BaseCurveConvex2.sol"; + +contract BUSDV2CurveConvex is BaseCurveConvex2 { + constructor() + BaseCurveConvex2( + Constants.CRV_BUSDV2_ADDRESS, + Constants.CRV_BUSDV2_LP_ADDRESS, + Constants.CVX_BUSDV2_REWARDS_ADDRESS, + Constants.CVX_BUSDV2_PID, + Constants.BUSD_ADDRESS, + address(1), + address(1), + address(1) + ) + {} +} diff --git a/contracts/mutants/BUSDV2CurveConvex/original/BUSDV2CurveConvex.sol b/contracts/mutants/BUSDV2CurveConvex/original/BUSDV2CurveConvex.sol new file mode 100644 index 00000000000..fa0a1a1d0e7 --- /dev/null +++ b/contracts/mutants/BUSDV2CurveConvex/original/BUSDV2CurveConvex.sol @@ -0,0 +1,20 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.8.4; + +import "../utils/Constants.sol"; +import "./BaseCurveConvex2.sol"; + +contract BUSDV2CurveConvex is BaseCurveConvex2 { + constructor() + BaseCurveConvex2( + Constants.CRV_BUSDV2_ADDRESS, + Constants.CRV_BUSDV2_LP_ADDRESS, + Constants.CVX_BUSDV2_REWARDS_ADDRESS, + Constants.CVX_BUSDV2_PID, + Constants.BUSD_ADDRESS, + address(0), + address(0), + address(0) + ) + {} +}